MongoDB\Driver\Cursor::getId() expects exactly 0 arguments, 1 given#390
Conversation
vanyabrovary
commented
Jun 24, 2025
| Q | A |
|---|---|
| Is bugfix? | ✔️ |
| New feature? | ❌ |
| Breaks BC? | ❌ |
| Fixed issues | (#388) |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug arising from passing an unexpected argument to the MongoDB driver's getId() method in several files.
- Removed the extraneous argument from the getId() call in Cursor.php
- Updated getId() calls in Query.php and BatchQueryResult.php to match the required method signature
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/file/Cursor.php | Fixed the call to getId() by removing the wrongly passed argument |
| src/Query.php | Corrected the getId() usage in logging to conform to the API |
| src/BatchQueryResult.php | Adjusted the getId() call in batch data fetching to avoid argument error |
| public function getId() | ||
| { | ||
| return $this->getInnerIterator()->getId(true); | ||
| return $this->getInnerIterator()->getId(); |
There was a problem hiding this comment.
Removed the unsupported argument from getId(), which now aligns with the MongoDB driver's expected method signature.
| return $this->getInnerIterator()->getId(); | |
| $innerIterator = $this->getInnerIterator(); | |
| if ($innerIterator instanceof \MongoDB\Driver\Cursor) { | |
| return $innerIterator->getId(); | |
| } | |
| throw new \RuntimeException('Inner iterator is not an instance of \MongoDB\Driver\Cursor.'); |
| protected function fetchRows($cursor, $all = true, $indexBy = null) | ||
| { | ||
| $token = 'fetch cursor id = ' . $cursor->getId(true); | ||
| $token = 'fetch cursor id = ' . $cursor->getId(); |
There was a problem hiding this comment.
Updated getId() by removing the extraneous argument to prevent runtime exceptions in logging.
| $token = 'fetch cursor id = ' . $cursor->getId(); | |
| $token = 'fetch cursor hash = ' . spl_object_hash($cursor); |
| $token = 'fetch cursor id = ' . $cursor->getId(); | ||
| Yii::info($token, __METHOD__); |
There was a problem hiding this comment.
Removed the invalid argument from the getId() call to fix the bug related to incorrect method usage.
| $token = 'fetch cursor id = ' . $cursor->getId(); | |
| Yii::info($token, __METHOD__); | |
| if (method_exists($cursor, 'getId')) { | |
| $token = 'fetch cursor id = ' . $cursor->getId(); | |
| Yii::info($token, __METHOD__); | |
| } else { | |
| Yii::warning('Cursor does not support getId()', __METHOD__); | |
| } |
|
Please add a line for CHANGELOG. We'll fix test pipelines to run it. |
|
Hi, I have the same issue. In the previous version (v3.0.2), there was a try/catch block to handle the difference in method signature between MongoDB extension versions (1.x vs 2.x). That fallback has been removed in 3.0.3, but it's still necessary for compatibility with the 2.x extension, where getId() no longer accepts any arguments. To support both extension versions, I suggest restoring the compatibility logic in the fetchRows() in yiisoft/yii2-mongodb/src/Query.php Let me know if you'd like me to submit a patch. |
|
Thank you! |
Or increase the minimum version of the MongoDB PHP extension to 2.0.0 |