Upgrade Library Version
On this page
Overview
On this page, you can learn how to upgrade Laravel MongoDB to a new major version. This page also includes the changes you must make to your application to upgrade your object-document mapper (ODM) version without losing functionality, if applicable.
How to Upgrade
Before you upgrade, perform the following actions:
Ensure the new library version is compatible with the MongoDB Server version your application connects to and the version of Laravel that your application runs on. See the Compatibility page for this information.
Address any breaking changes between the version of the Laravel Integration that your application now uses and your planned upgrade version in the Breaking Changes section of this guide.
To upgrade your library version, run the following command in your application's directory:
composer require mongodb/laravel-mongodb:4.8
To upgrade to a different version of the library, replace the information after
laravel-mongodb:
with your preferred version number.
Breaking Changes
A breaking change is a modification in a convention or behavior in a specific version of the Laravel Integration that might prevent your application from working as expected.
The breaking changes in this section are categorized by the major version releases that introduced them. When upgrading library versions, address all the breaking changes between your current version and the planned upgrade version.
Version 4.x Breaking Changes
This library version introduces the following breaking changes:
Minimum Laravel version is now 10.0. For instructions on upgrading your Laravel version, see the Upgrade Guide in the Laravel documentation.
Dependency name is now
"mongodb/laravel-mongodb"
. Ensure that the dependency name in yourcomposer.json
file is"mongodb/laravel-mongodb": "^4.0"
. Then, runcomposer update
.Namespace is now
MongoDB\Laravel\
. Ensure that you change the namespace fromJenssegers\Mongodb\
toMongoDB\Laravel\
in your models and config files.Removes support for non-Laravel projects.
Removes support for the
$dates
property. Ensure that you change all instances of$dates
to$casts
in your model files.Model::unset($field)
does not persist the change. Ensure that you follow all calls toModel::unset($field)
withModel::save()
.Removes the
Query\Builder::whereAll($column, $values)
method. Ensure that you replace all calls toQuery\Builder::whereAll($column, $values)
withQuery\Builder::where($column, 'all', $values)
.Query\Builder::delete()
can delete one or all documents. Ensure that you pass only the values1
ornull
tolimit()
.whereDate()
,whereDay()
,whereMonth()
,whereYear()
, andwhereTime()
methods now use MongoDB operators on date fields.Adds the
MongoDB\Laravel\Eloquent\MassPrunable
trait. Ensure that you replace all instances ofIlluminate\Database\Eloquent\MassPrunable
withMongoDB\Laravel\Eloquent\MassPrunable
in your models.Removes support for the following
Query\Builder
methods:toSql()
toRawSql()
whereColumn()
whereFullText()
groupByRaw()
orderByRaw()
unionAll()
union()
having()
havingRaw()
havingBetween()
whereIntegerInRaw()
orWhereIntegerInRaw()
whereIntegerNotInRaw()
orWhereIntegerNotInRaw()