Skip to content

Commit 747f813

Browse files
authored
Merge branch '5.0' into DOCSP-43159-query-builder-returns-object
2 parents fd00783 + 6507279 commit 747f813

26 files changed

+197
-179
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ All notable changes to this project will be documented in this file.
44
## [5.0.0] - next
55

66
* Remove support for Laravel 10 by @GromNaN in [#3123](https://github.com/mongodb/laravel-mongodb/pull/3123)
7-
* **BREAKING CHANGE** Use `id` as an alias for `_id` in commands and queries for compatibility with Eloquent packages by @GromNaN in [#3040](https://github.com/mongodb/laravel-mongodb/pull/3040)
7+
* **BREAKING CHANGE** Use `id` as an alias for `_id` in commands and queries for compatibility with Eloquent packages by @GromNaN in [#3040](https://github.com/mongodb/laravel-mongodb/pull/3040) and [#3136](https://github.com/mongodb/laravel-mongodb/pull/3136)
88
* **BREAKING CHANGE** Make Query\Builder return objects instead of array to match Laravel behavior by @GromNaN in [#3107](https://github.com/mongodb/laravel-mongodb/pull/3107)
99
* **BREAKING CHANGE** In DB query results, convert BSON `UTCDateTime` objects into `Carbon` date with the default timezone by @GromNaN in [#3119](https://github.com/mongodb/laravel-mongodb/pull/3119)
1010
* Remove `MongoFailedJobProvider`, replaced by Laravel `DatabaseFailedJobProvider` by @GromNaN in [#3122](https://github.com/mongodb/laravel-mongodb/pull/3122)
1111
* Remove custom `PasswordResetServiceProvider`, use the default `DatabaseTokenRepository` by @GromNaN in [#3124](https://github.com/mongodb/laravel-mongodb/pull/3124)
1212
* Remove `Blueprint::background()` method by @GromNaN in [#3132](https://github.com/mongodb/laravel-mongodb/pull/3132)
13+
* Replace `Collection` proxy class with Driver monitoring by @GromNaN in [#3137]((https://github.com/mongodb/laravel-mongodb/pull/3137)
1314

1415
## [4.8.0] - 2024-08-27
1516

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"illuminate/database": "^11",
3131
"illuminate/events": "^11",
3232
"illuminate/support": "^11",
33-
"mongodb/mongodb": "^1.15"
33+
"mongodb/mongodb": "^1.18"
3434
},
3535
"require-dev": {
3636
"mongodb/builder": "^0.2",
@@ -41,7 +41,8 @@
4141
"mockery/mockery": "^1.4.4",
4242
"doctrine/coding-standard": "12.0.x-dev",
4343
"spatie/laravel-query-builder": "^5.6",
44-
"phpstan/phpstan": "^1.10"
44+
"phpstan/phpstan": "^1.10",
45+
"rector/rector": "^1.2"
4546
},
4647
"suggest": {
4748
"league/flysystem-gridfs": "Filesystem storage in MongoDB with GridFS",
@@ -73,7 +74,8 @@
7374
"test": "phpunit",
7475
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
7576
"cs": "phpcs",
76-
"cs:fix": "phpcbf"
77+
"cs:fix": "phpcbf",
78+
"rector": "rector"
7779
},
7880
"config": {
7981
"allow-plugins": {

docs/eloquent-models/model-class.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,8 @@ including this trait, you can make the third-party class compatible with
302302
MongoDB.
303303

304304
When you apply the ``DocumentModel`` trait to a model class, you must
305-
declare the following properties in your class:
306-
307-
- ``$primaryKey = '_id'``, because the ``_id`` field uniquely
308-
identifies MongoDB documents
309-
- ``$keyType = 'string'``, because the {+odm-short+} casts MongoDB
310-
``ObjectId`` values to type ``string``
305+
set the ``$keyType`` property to ``'string'`` as the {+odm-short+}
306+
casts MongoDB ``ObjectId`` values to type ``string``.
311307

312308
Extended Class Example
313309
~~~~~~~~~~~~~~~~~~~~~~

docs/includes/query-builder/QueryBuilderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
use Illuminate\Database\Query\Builder;
88
use Illuminate\Pagination\AbstractPaginator;
99
use Illuminate\Support\Facades\DB;
10+
use MongoDB\BSON\ObjectId;
1011
use MongoDB\BSON\Regex;
11-
use MongoDB\Laravel\Collection;
12+
use MongoDB\Collection;
1213
use MongoDB\Laravel\Tests\TestCase;
1314

1415
use function file_get_contents;
@@ -63,7 +64,7 @@ public function testOrWhere(): void
6364
// begin query orWhere
6465
$result = DB::connection('mongodb')
6566
->table('movies')
66-
->where('year', 1955)
67+
->where('id', new ObjectId('573a1398f29313caabce9682'))
6768
->orWhere('title', 'Back to the Future')
6869
->get();
6970
// end query orWhere

docs/includes/usage-examples/FindOneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public function testFindOne(): void
3131
// end-find-one
3232

3333
$this->assertInstanceOf(Movie::class, $movie);
34-
$this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
34+
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
3535
}
3636
}

docs/query-builder.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,28 @@ Logical OR Example
181181

182182
The following example shows how to chain the ``orWhere()``
183183
query builder method to retrieve documents from the
184-
``movies`` collection that either match the ``year``
185-
value of ``1955`` or match the ``title`` value ``"Back to the Future"``:
184+
``movies`` collection in which the value of the ``_id``
185+
field is ``ObjectId('573a1398f29313caabce9682')`` or
186+
the value of the ``title`` field is ``"Back to the Future"``:
186187

187188
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
188189
:language: php
189190
:dedent:
190191
:start-after: begin query orWhere
191192
:end-before: end query orWhere
192193

194+
.. note::
195+
196+
You can use the ``id`` alias in your queries to represent the
197+
``_id`` field in MongoDB documents, as shown in the preceding
198+
code. When you run a find operation using the query builder, {+odm-short+}
199+
automatically converts between ``id`` and ``_id``. This provides better
200+
compatibility with Laravel, as the framework assumes that each record has a
201+
primary key named ``id`` by default.
202+
203+
Because of this behavior, you cannot have two separate ``id`` and ``_id``
204+
fields in your documents.
205+
193206
.. _laravel-query-builder-logical-and:
194207

195208
Logical AND Example

docs/upgrade.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,24 @@ This library version introduces the following breaking changes:
9191
// v5.0
9292
$document->balance;
9393

94+
- Removes support for the following classes:
95+
96+
- ``MongoDB\Laravel\Auth\DatabaseTokenRepository``. Instead, use the default
97+
``Illuminate\Queue\Failed\DatabaseFailedJobProvider`` class and
98+
specify a connection to MongoDB.
99+
100+
- ``MongoDB\Laravel\Queue\Failed\MongoFailedJobProvider``. Instead,
101+
use the default ``Illuminate\Queue\Failed\DatabaseFailedJobProvider``
102+
class and specify a connection to MongoDB.
103+
94104
- In query results, the library converts BSON ``UTCDateTime`` objects to ``Carbon``
95105
date classes, applying the default timezone.
96106

107+
- ``id`` is an alias for the ``_id`` field in MongoDB documents, and the library
108+
automatically converts between ``id`` and ``_id`` when querying data. Because
109+
of this behavior, you cannot have two separate ``id`` and ``_id`` fields in your
110+
documents.
111+
97112
.. _laravel-breaking-changes-v4.x:
98113

99114
Version 4.x Breaking Changes

rector.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Rector\Config\RectorConfig;
4+
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
5+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
6+
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
7+
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
8+
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
9+
10+
return RectorConfig::configure()
11+
->withPaths([
12+
__FILE__,
13+
__DIR__ . '/docs',
14+
__DIR__ . '/src',
15+
__DIR__ . '/tests',
16+
])
17+
->withPhpSets()
18+
->withTypeCoverageLevel(0)
19+
->withSkip([
20+
RemoveExtraParametersRector::class,
21+
ClosureToArrowFunctionRector::class,
22+
NullToStrictStringFuncCallArgRector::class,
23+
MixedTypeRector::class,
24+
AddClosureVoidReturnTypeWhereNoReturnRector::class,
25+
]);

src/Bus/MongoBatchRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Illuminate\Support\Carbon;
1515
use MongoDB\BSON\ObjectId;
1616
use MongoDB\BSON\UTCDateTime;
17+
use MongoDB\Collection;
1718
use MongoDB\Driver\ReadPreference;
18-
use MongoDB\Laravel\Collection;
1919
use MongoDB\Laravel\Connection;
2020
use MongoDB\Operation\FindOneAndUpdate;
2121
use Override;
@@ -28,7 +28,7 @@
2828
// are called by PruneBatchesCommand
2929
class MongoBatchRepository extends DatabaseBatchRepository implements PrunableBatchRepository
3030
{
31-
private Collection $collection;
31+
private readonly Collection $collection;
3232

3333
public function __construct(
3434
BatchFactory $factory,

src/Cache/MongoLock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Support\Carbon;
77
use InvalidArgumentException;
88
use MongoDB\BSON\UTCDateTime;
9-
use MongoDB\Laravel\Collection;
9+
use MongoDB\Collection;
1010
use MongoDB\Operation\FindOneAndUpdate;
1111
use Override;
1212

0 commit comments

Comments
 (0)