This member function:
unsigned long long count (const string &ns, const BSONObj &query=BSONObj(), int options=0)
only allows a BSONObj for query. Feature request: Allow complex Query objects (mongo::Query::isComplex == true).
Work-arounds: Strip out complexity:
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).