Server-side Query count

25 views
Skip to first unread message

Therefore

unread,
Sep 6, 2012, 3:32:48 PM9/6/12
to mongo...@googlegroups.com
Windows 7 64 SP1
MongoDB 2.2.0-rc2
Boost 1.42
MS VS 2010 Ultimate
C++ driver

I apologize if this is the incorrect forum -- the answer I received on MongoDB-user was to raise a jira ticket or release a C++ driver and submit a pull request. However the problem is a deficiency in my understanding and not a deficiency in MongoDB.

I have a function that takes a Query object as a parameter:

      someFunction( Query qu )

Advantages:

   1. Can accept either a Query object or a well-formed BSONObj.
   2. Have access to Query helpers such as sort/hint/etc.

Disadvantage:

   1. Can't do a server-side count (vs. a client-side count of a batch of results) akin to:

      nstudents = db.students.find({'address.state' : 'CA'}).count();

      i.e.,

      unsigned long long n = c.count("mydb.users", qu);

      raises the error:

      cannot convert ... from 'mongo::Query' to 'const mongo::BSONObj &

So, it was suggested I use a BSONObj as a parameter:

      someFunction ( BSONObj qu )

Advantages:

    1. Can do a server side count.
    2. Can convert to a Query and hence use its helpers.

Disadvantage:

     1.  Anyone using the function must be aware not to pass a query as a Query object which is counter-intuitive.

So, my naive questions are:

Why aren't the helper methods of the Query class implemented in BSONObj? Or, conversely, why couldn't a server-side count method be implemented with the Query class?

Thanks -- and again, if this is the inappropriate forum, I'll shuffle along. :)

Mark
Reply all
Reply to author
Forward
0 new messages