diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-10-28 13:47:02 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-10-28 13:47:30 -0400 |
commit | db4569cc56dec17e2630a18c68baee254da7c597 (patch) | |
tree | 7b58601a072d7dddbf270a7a1280d59676fad796 | |
parent | 876dae7981e1ec1141fd1b155429274b83a1f99c (diff) | |
download | mongo-db4569cc56dec17e2630a18c68baee254da7c597.tar.gz |
count takes skip/limit
-rw-r--r-- | client/dbclient.cpp | 11 | ||||
-rw-r--r-- | client/dbclient.h | 2 |
2 files changed, 10 insertions, 3 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 2849dc330a6..41b75985bfe 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -222,9 +222,16 @@ namespace mongo { return runCommand(dbname, b.done(), *info); } - unsigned long long DBClientWithCommands::count(const string &_ns, const BSONObj& query, int options) { + unsigned long long DBClientWithCommands::count(const string &_ns, const BSONObj& query, int options, int limit, int skip ) { NamespaceString ns(_ns); - BSONObj cmd = BSON( "count" << ns.coll << "query" << query ); + BSONObjBuilder b; + b.append( "count" , ns.coll ); + b.append( "query" , query ); + if ( limit ) + b.append( "limit" , limit ); + if ( skip ) + b.append( "skip" , skip ); + BSONObj cmd = b.obj(); BSONObj res; if( !runCommand(ns.db.c_str(), cmd, res, options) ) uasserted(11010,string("count fails:") + res.toString()); diff --git a/client/dbclient.h b/client/dbclient.h index b11a431b494..eaa63944423 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -412,7 +412,7 @@ namespace mongo { /** count number of objects in collection ns that match the query criteria specified throws UserAssertion if database returns an error */ - unsigned long long count(const string &ns, const BSONObj& query = BSONObj(), int options=0 ); + unsigned long long count(const string &ns, const BSONObj& query = BSONObj(), int options=0, int limit=0, int skip=0 ); string createPasswordDigest( const string &username , const string &clearTextPassword ); |