-
-
Notifications
You must be signed in to change notification settings - Fork 194
MongoDB\Driver\Cursor::getId() expects exactly 0 arguments, 1 given #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
Copilot
AI
Jun 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.'); |
Copilot uses AI. Check for mistakes.
protected function fetchRows($cursor, $all = true, $indexBy = null) | ||
{ | ||
$token = 'fetch cursor id = ' . $cursor->getId(true); | ||
$token = 'fetch cursor id = ' . $cursor->getId(); |
Copilot
AI
Jun 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
Copilot uses AI. Check for mistakes.
$token = 'fetch cursor id = ' . $cursor->getId(); | ||
Yii::info($token, __METHOD__); |
Copilot
AI
Jun 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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__); | |
} |
Copilot uses AI. Check for mistakes.
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 |