You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: support db.coll.count() and cursor count/itcount/size (#28)
* feat: support db.coll.count() and cursor count/itcount/size
Adds the deprecated-but-heavily-used count() forms by routing through the
modern driver methods:
- db.coll.count() (zero args) -> EstimatedDocumentCount, preserving the
fast metadata path mongosh users expect on large collections.
- db.coll.count(filter, opts?) -> CountDocuments, the only correct option
once a filter is involved (EstimatedDocumentCount cannot take a filter).
- cursor.count() / itcount() / size() on a find cursor -> CountDocuments
with the accumulated filter/skip/limit/hint. Modern mongosh always
honors skip/limit on cursor.count, so we do too.
Aggregate-cursor itcount() requires pipeline rewriting ($count stage)
and is left unsupported until telemetry shows demand.
Motivated by gomongo-fallback telemetry from production: count() forms
account for the largest single bucket of mongosh fallbacks. Removing
them is a prerequisite for retiring the mongosh fallback path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* review: reject cursor count/itcount/size args; tighten unsupported assert
Address Copilot review feedback on PR #28.
- translate.go: cursor count/itcount/size now reject any positional
arguments rather than silently dropping them. mongosh's legacy
cursor.count(applySkipLimit) boolean is a no-op in modern drivers
(skip/limit always apply), so accepting it would make incorrect
caller assumptions hard to debug. Updated comment to spell out
*why* the OpType is retargeted instead of running find then count
on the cursor (mongosh issues a separate count command, never
iterates).
- collection_test.go: TestAggregateItcountUnsupported now asserts the
Operation field on the error so a different unsupported method
can't slip past as a false positive.
- Adds TestCursorCountRejectsArgs covering count(true)/count(false)/
itcount(true)/size(1).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments