Skip to content

feat: add cursor.count() deprecation error#11

Merged
h3n4l merged 1 commit intomainfrom
vk/bd54-gomongo-mileston
Jan 19, 2026
Merged

feat: add cursor.count() deprecation error#11
h3n4l merged 1 commit intomainfrom
vk/bd54-gomongo-mileston

Conversation

@h3n4l
Copy link
Member

@h3n4l h3n4l commented Jan 19, 2026

Summary

  • Return a helpful error message when cursor.count() is used
  • Direct users to use countDocuments() or estimatedDocumentCount() instead

Error Message

unsupported operation "count()": MongoDB drivers deprecate their respective cursor and collection count() APIs in favor of countDocuments() and estimatedDocumentCount()

Rationale

MongoDB drivers deprecate their respective cursor and collection count() APIs in favor of new APIs that correspond to countDocuments() and estimatedDocumentCount(). Rather than supporting a deprecated method, we return a clear error message guiding users to the recommended alternatives.

Test plan

  • Integration test verifies deprecation error is returned
  • Error message contains count(), countDocuments(), and estimatedDocumentCount()
  • All existing tests pass
  • Linting clean

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 19, 2026 08:55
Copy link

Copilot AI left a 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 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 opCount operation type for cursor count operations
  • Implemented executeCount() function that uses CountDocuments() 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>
@h3n4l h3n4l force-pushed the vk/bd54-gomongo-mileston branch from b3adfb3 to 942d7db Compare January 19, 2026 09:22
@h3n4l h3n4l changed the title feat: add cursor.count() operation support feat: add cursor.count() deprecation error Jan 19, 2026
@d-bytebase d-bytebase requested a review from rebelice January 19, 2026 09:27
@h3n4l h3n4l merged commit ae498c8 into main Jan 19, 2026
2 checks passed
@h3n4l h3n4l deleted the vk/bd54-gomongo-mileston branch January 19, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants