unsigned long long DBDirectClient::count(const string& ns, const BSONObj& query, int options, int limit, int skip) { if (skip < 0) { warning() << "setting negative skip value: " << skip << " to zero in query: " << query << endl; skip = 0; } Lock::DBRead lk(_txn->lockState(), ns); string errmsg; int errCode; long long res = runCount(_txn, ns, _countCmd(ns, query, options, limit, skip), errmsg, errCode); if (res == -1) { // namespace doesn't exist return 0; } massert(errCode, str::stream() << "count failed in DBDirectClient: " << errmsg , res >= 0); return (unsigned long long )res; }
unsigned long long DBClientWithCommands::count(const string &myns, const BSONObj& query, int options, int limit, int skip ) { NamespaceString ns(myns); BSONObj cmd = _countCmd( myns , query , options , limit , skip ); BSONObj res; if( !runCommand(ns.db.c_str(), cmd, res, options) ) uasserted(11010,string("count fails:") + res.toString()); return res["n"].numberLong(); }
unsigned long long DBDirectClient::count(const string &ns, const BSONObj& query, int options, int limit, int skip ) { Lock::DBRead lk( ns ); string errmsg; long long res = runCount( ns.c_str() , _countCmd( ns , query , options , limit , skip ) , errmsg ); if ( res == -1 ) return 0; uassert( 13637 , str::stream() << "count failed in DBDirectClient: " << errmsg , res >= 0 ); return (unsigned long long )res; }
unsigned long long DBDirectClient::count(const string &ns, const BSONObj& query, int options, int limit, int skip ) { Lock::DBRead lk( ns ); string errmsg; int errCode; long long res = runCount( ns.c_str() , _countCmd( ns , query , options , limit , skip ) , errmsg, errCode ); if ( res == -1 ) { // namespace doesn't exist return 0; } massert( errCode , str::stream() << "count failed in DBDirectClient: " << errmsg , res >= 0 ); return (unsigned long long )res; }
unsigned long long DBDirectClient::count(const string &ns, const BSONObj& query, int options, int limit, int skip ) { if ( skip < 0 ) { warning() << "setting negative skip value: " << skip << " to zero in query: " << query << endl; skip = 0; } string errmsg; int errCode; LOCK_REASON(lockReason, "count"); Client::ReadContext ctx(ns, lockReason); Client::Transaction transaction(DB_TXN_SNAPSHOT | DB_TXN_READ_ONLY); long long res = runCount( ns.c_str() , _countCmd( ns , query , options , limit , skip ) , errmsg, errCode ); if ( res == -1 ) { // namespace doesn't exist return 0; } massert( errCode , str::stream() << "count failed in DBDirectClient: " << errmsg , res >= 0 ); transaction.commit(); return (unsigned long long )res; }