[SERVER-7716] change DBClientWithCommands count() to take a Query instead of a BSON object Created: 20/Nov/12  Updated: 07/Jan/17  Resolved: 07/Jan/17

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 2.3.0
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: George Thompson Assignee: Andrew Morrow (Inactive)
Resolution: Won't Fix Votes: 0
Labels: driver, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7 64 SP1
MongoDB 2.2.0
MS VS 2010
C++ driver


Backwards Compatibility: Fully Compatible
Sprint: Platforms 2017-01-23
Participants:

 Description   

This member function:

unsigned long long count (const string &ns, const BSONObj &query=BSONObj(), int options=0)

of

mongo::DBClientWithCommands

only allows a BSONObj for query. Feature request: Allow complex Query objects (mongo::Query::isComplex == true).

Work-arounds: Strip out complexity:

query.obj["query"].embeddedObject()

and use that as the parameter to count() when isComplex == true (useful in functions that accept complex Query objects). Or build an interim non-complex query, use that with count() and then add in sort, explain, etc.

Arguably, this is unnecessary complexity. Allowing a Query object will be consistent with a member function that counts the "number of objects ... that match the query." You could change the parameter to &query=Query() as it should continue to accept BSONObj objects, so no compatibility issues (that I can thank of).



 Comments   
Comment by Andrew Morrow (Inactive) [ 07/Jan/17 ]

This ticket was filed to make an improvement to the C++ driver which used to be part of the server source code. During MongoDB 2.5 development, the C++ driver was separated out into a dedicated github repo. Since that time, an entirely new C++ driver has been written using modern C++ development idioms, and up-to-date MongoDB Driver specifications.

While some of the code referenced here does continue to live in the server, we are no longer making improvements to that code. Improvements to the C++ driver should no be made against the various branches in the new repository.

Comment by Kolibaba Sergey [ 28/Dec/16 ]

good day
here github link pull request with possible improvement

Generated at Thu Feb 08 03:15:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.