本文整理汇总了C++中DBDirectClient::count方法的典型用法代码示例。如果您正苦于以下问题:C++ DBDirectClient::count方法的具体用法?C++ DBDirectClient::count怎么用?C++ DBDirectClient::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBDirectClient
的用法示例。
在下文中一共展示了DBDirectClient::count方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run() {
// Recreate the collection as capped, without an _id index.
_client.dropCollection( _ns );
BSONObj info;
ASSERT( _client.runCommand( "unittests",
BSON( "create" << "indexupdate" <<
"capped" << true <<
"size" << ( 10 * 1024 ) <<
"autoIndexId" << false ),
info ) );
// Insert some documents.
int32_t nDocs = 1000;
for( int32_t i = 0; i < nDocs; ++i ) {
_client.insert( _ns, BSON( "_id" << i ) );
}
// Initialize curop.
cc().curop()->reset();
// Request an interrupt.
killCurrentOp.killAll();
BSONObj indexInfo = BSON( "key" << BSON( "_id" << 1 ) <<
"ns" << _ns <<
"name" << "_id" );
// The call is not interrupted because mayInterrupt == false.
theDataFileMgr.insertWithObjMod( "unittests.system.indexes", indexInfo, false );
// The new index is listed in system.indexes because the index build succeeded.
ASSERT_EQUALS( 1U, _client.count( "unittests.system.indexes", BSON( "ns" << _ns ) ) );
}
示例2: checkIfReplMissingFromCommandLine
/**
* Checks if this server was started without --replset but has a config in local.system.replset
* (meaning that this is probably a replica set member started in stand-alone mode).
*
* @returns the number of documents in local.system.replset or 0 if this was started with
* --replset.
*/
unsigned long long checkIfReplMissingFromCommandLine() {
Lock::GlobalWrite lk; // this is helpful for the query below to work as you can't open files when readlocked
if (!replSettings.usingReplSets()) {
DBDirectClient c;
return c.count("local.system.replset");
}
return 0;
}
示例3: checkIfReplMissingFromCommandLine
void checkIfReplMissingFromCommandLine() {
Lock::GlobalWrite lk; // _openAllFiles is false at this point, so this is helpful for the query below to work as you can't open files when readlocked
if( !cmdLine.usingReplSets() ) {
Client::GodScope gs;
DBDirectClient c;
unsigned long long x =
c.count("local.system.replset");
if( x ) {
log() << endl;
log() << "** warning: mongod started without --replSet yet " << x << " documents are present in local.system.replset" << endl;
log() << "** restart with --replSet unless you are doing maintenance and no other clients are connected" << endl;
log() << endl;
}
}
}
示例4: run
void run() {
// RARELY shoud be once/128x
for (int i=0; i<150; i++) {
insert();
updateSucceed();
}
DBDirectClient client;
int count = (int) client.count(cappedNs(), BSONObj());
verify(count > 1);
// Just to be sure, no _id index, right?
Client::Context ctx(cappedNs());
NamespaceDetails *nsd = nsdetails(cappedNs().c_str());
verify(nsd->findIdIndex() == -1);
}
示例5: run
void run() {
// Insert some documents.
int32_t nDocs = 1000;
for( int32_t i = 0; i < nDocs; ++i ) {
_client.insert( _ns, BSON( "a" << i ) );
}
// Initialize curop.
cc().curop()->reset();
// Request an interrupt.
killCurrentOp.killAll();
// The call is not interrupted.
Helpers::ensureIndex( _ns, BSON( "a" << 1 ), false, "a_1" );
// The new index is listed in system.indexes because the index build completed.
ASSERT_EQUALS( 1U,
_client.count( "unittests.system.indexes",
BSON( "ns" << _ns << "name" << "a_1" ) ) );
}
示例6: run
void run() {
// Insert some documents.
int32_t nDocs = 1000;
for( int32_t i = 0; i < nDocs; ++i ) {
_client.insert( _ns, BSON( "a" << i ) );
}
// Initialize curop.
cc().curop()->reset();
// Request an interrupt. killAll() rather than kill() is required because the direct
// client will build the index using a new opid.
killCurrentOp.killAll();
// The call is not interrupted.
_client.ensureIndex( _ns, BSON( "a" << 1 ) );
// only want to interrupt the index build
killCurrentOp.reset();
// The new index is listed in system.indexes because the index build completed.
ASSERT_EQUALS( 1U,
_client.count( "unittests.system.indexes",
BSON( "ns" << _ns << "name" << "a_1" ) ) );
}
示例7: conn
ReplSetConfig::ReplSetConfig(const HostAndPort& h) {
clear();
int level = 2;
DEV level = 0;
BSONObj cfg;
int v = -5;
try {
if( h.isSelf() ) {
;
}
else {
/* first, make sure other node is configured to be a replset. just to be safe. */
string setname = cmdLine.ourSetName();
BSONObj cmd = BSON( "replSetHeartbeat" << setname );
int theirVersion;
BSONObj info;
log() << "trying to contact " << h.toString() << rsLog;
bool ok = requestHeartbeat(setname, "", h.toString(), info, -2, theirVersion);
if( info["rs"].trueValue() ) {
// yes, it is a replicate set, although perhaps not yet initialized
}
else {
if( !ok ) {
log() << "replSet TEMP !ok heartbeating " << h.toString() << " on cfg load" << rsLog;
if( !info.isEmpty() )
log() << "replSet info " << h.toString() << " : " << info.toString() << rsLog;
return;
}
{
stringstream ss;
ss << "replSet error: member " << h.toString() << " is not in --replSet mode";
msgassertedNoTrace(13260, ss.str().c_str()); // not caught as not a user exception - we want it not caught
//for python err# checker: uassert(13260, "", false);
}
}
}
v = -4;
unsigned long long count = 0;
try {
ScopedConn conn(h.toString());
v = -3;
cfg = conn.findOne(rsConfigNs, Query()).getOwned();
count = conn.count(rsConfigNs);
}
catch ( DBException& ) {
if ( !h.isSelf() ) {
throw;
}
// on startup, socket is not listening yet
DBDirectClient cli;
cfg = cli.findOne( rsConfigNs, Query() ).getOwned();
count = cli.count(rsConfigNs);
}
if( count > 1 )
uasserted(13109, str::stream() << "multiple rows in " << rsConfigNs << " not supported host: " << h.toString());
if( cfg.isEmpty() ) {
version = EMPTYCONFIG;
return;
}
version = -1;
}
catch( DBException& e) {
version = v;
log(level) << "replSet load config couldn't get from " << h.toString() << ' ' << e.what() << rsLog;
return;
}
from(cfg);
checkRsConfig();
_ok = true;
log(level) << "replSet load config ok from " << (h.isSelf() ? "self" : h.toString()) << rsLog;
}