Skip to content

Commit 766dfa5

Browse files
authored
Fix #379, fix #382: Fixed usage of getId method in BatchQueryResult and Cursor classes to match changes in MongoDB PHP Extension 1.20.1, MongoDB PHP extension min version raised up to 1.20.1
1 parent 7d344d3 commit 766dfa5

File tree

9 files changed

+26
-19
lines changed

9 files changed

+26
-19
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
os: [ubuntu-latest]
21-
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
22-
mongo: ['3']
23-
mongoext: ['1.8.2', '1.9.0']
21+
php: ['7.4', '8.0', '8.1']
22+
mongo: ['4.0']
23+
mongoext: ['1.20.1']
2424

2525
steps:
2626
- name: Checkout

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Yii Framework 2 mongodb extension Change Log
44
3.0.3 under development
55
-----------------------
66

7-
- no changes in this release.
7+
- Bug #379, #382: Fixed usage of `getId` method in BatchQueryResult and Cursor classes to match changes in MongoDB PHP Extension 1.20.1 (shaperman)
8+
- Chg: MongoDB PHP extension min version raised up to 1.20.1 (shaperman)
89

910

1011
3.0.2 February 13, 2025

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
2020
Installation
2121
------------
2222

23-
This extension requires [MongoDB PHP Extension](https://www.php.net/manual/en/set.mongodb.php) version 1.0.0 or higher.
23+
This extension requires [MongoDB PHP Extension](https://www.php.net/manual/en/set.mongodb.php) version 1.20.1 or higher.
2424

25-
This extension requires MongoDB server version 3.0 or higher.
25+
This extension requires MongoDB server version 4.0 or higher.
2626

2727
The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
2828

@@ -60,3 +60,10 @@ return [
6060
],
6161
];
6262
```
63+
64+
Known issues
65+
------------
66+
<ul>
67+
<li>yii\mongodb\Exception: no such command: 'group' with MongoDB server version 4.2 or higher.<br/>
68+
Starting in version 4.2, MongoDB removes the group command (deprecated since version 3.4) and its mongo shell helper db.collection.group().</li>
69+
</ul>

UPGRADE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ if you want to upgrade from version A to version C and there is
88
version B between A and C, you need to following the instructions
99
for both A and B.
1010

11+
Upgrade from 3.0.2
12+
----------------------
13+
* MongoDB PHP extension min version raised up to 1.20.1. You should upgrade your environment in case you are
14+
using older version.
15+
* MongoDB server versions < 4.0 are no longer supported. Make sure you are running MongoDB server >= 4.0
16+
1117
Upgrade from 2.1.9
1218
----------------------
1319

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"yiisoft/yii2": "~2.0.39",
22-
"ext-mongodb": ">=1.0.0",
22+
"ext-mongodb": ">=1.20.1",
2323
"paragonie/random_compat": ">=1"
2424
},
2525
"require-dev": {

src/BatchQueryResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected function fetchData()
129129
if ($this->_iterator === null) {
130130
$this->query->addOptions(['batchSize' => $this->batchSize]);
131131
$cursor = $this->query->buildCursor($this->db);
132-
$token = 'fetch cursor id = ' . $cursor->getId();
132+
$token = 'fetch cursor id = ' . $cursor->getId(true);
133133
Yii::info($token, __METHOD__);
134134

135135
if ($cursor instanceof \Iterator) {

src/Query.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,7 @@ public function buildCursor($db = null)
212212
*/
213213
protected function fetchRows($cursor, $all = true, $indexBy = null)
214214
{
215-
try {
216-
# MongoDB >= 1.20
217-
$token = 'fetch cursor id = ' . $cursor->getId(true);
218-
} catch (\ArgumentCountError $e) {
219-
# MongoDB < 1.20
220-
$token = 'fetch cursor id = ' . $cursor->getId();
221-
}
222-
215+
$token = 'fetch cursor id = ' . $cursor->getId(true);
223216
Yii::info($token, __METHOD__);
224217
try {
225218
Yii::beginProfile($token, __METHOD__);

src/file/Cursor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public function toArray()
7878

7979
/**
8080
* Returns the ID for this cursor.
81-
* @return \MongoDB\Driver\CursorId cursor ID.
81+
* @return \MongoDB\BSON\Int64 cursor ID.
8282
*/
8383
public function getId()
8484
{
85-
return $this->getInnerIterator()->getId();
85+
return $this->getInnerIterator()->getId(true);
8686
}
8787

8888
/**

tests/QueryRunTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ public function testDistinct()
634634
->from('customer')
635635
->distinct('group', $db);
636636

637-
$this->assertSame(['odd', 'even'], $rows);
637+
$this->assertEquals(['odd', 'even'], $rows, '', 0.0, 10, true);
638638
}
639639

640640
public function testAggregationShortcuts()

0 commit comments

Comments
 (0)