Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for the deprecated MongoDB cursor.count() operation to enable backward compatibility with existing MongoDB shell scripts. The implementation allows counting documents matching a find() query while respecting skip() and limit() cursor modifiers.
Changes:
- Added
opCountoperation type for cursor count operations - Implemented
executeCount()function that usesCountDocuments()with skip/limit options - Added comprehensive test coverage for various count scenarios including filters, skip/limit modifiers, empty collections, and bracket notation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| translator.go | Added opCount constant and translator logic to detect count() method calls on cursors |
| executor.go | Implemented executeCount() function that executes count operations with filter, skip, and limit support |
| executor_test.go | Added 5 comprehensive test functions covering basic count, filters, skip/limit, empty collections, and bracket notation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Return a helpful error message when cursor.count() is used, directing users to use countDocuments() or estimatedDocumentCount() instead. MongoDB drivers deprecate their respective cursor and collection count() APIs in favor of countDocuments() and estimatedDocumentCount(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
b3adfb3 to
942d7db
Compare
rebelice
approved these changes
Jan 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cursor.count()is usedcountDocuments()orestimatedDocumentCount()insteadError Message
Rationale
MongoDB drivers deprecate their respective cursor and collection
count()APIs in favor of new APIs that correspond tocountDocuments()andestimatedDocumentCount(). Rather than supporting a deprecated method, we return a clear error message guiding users to the recommended alternatives.Test plan
count(),countDocuments(), andestimatedDocumentCount()🤖 Generated with Claude Code