本文整理汇总了C++中BSONObj::getBoolField方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::getBoolField方法的具体用法?C++ BSONObj::getBoolField怎么用?C++ BSONObj::getBoolField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObj
的用法示例。
在下文中一共展示了BSONObj::getBoolField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
virtual bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
string coll = cmdObj[ "captrunc" ].valuestrsafe();
uassert( 13416, "captrunc must specify a collection", !coll.empty() );
NamespaceString nss( dbname, coll );
int n = cmdObj.getIntField( "n" );
bool inc = cmdObj.getBoolField( "inc" ); // inclusive range?
Client::WriteContext ctx(txn, nss.ns() );
Collection* collection = ctx.ctx().db()->getCollection( txn, nss.ns() );
massert( 13417, "captrunc collection not found or empty", collection);
boost::scoped_ptr<Runner> runner(InternalPlanner::collectionScan(txn,
nss.ns(),
collection,
InternalPlanner::BACKWARD));
DiskLoc end;
// We remove 'n' elements so the start is one past that
for( int i = 0; i < n + 1; ++i ) {
Runner::RunnerState state = runner->getNext(NULL, &end);
massert( 13418, "captrunc invalid n", Runner::RUNNER_ADVANCED == state);
}
collection->temp_cappedTruncateAfter( txn, end, inc );
ctx.commit();
return true;
}
示例2: run
bool run(const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
log() << "test only command sleep invoked" << endl;
long long millis = 10 * 1000;
if (cmdObj["secs"].isNumber() && cmdObj["millis"].isNumber()) {
millis = cmdObj["secs"].numberLong() * 1000 + cmdObj["millis"].numberLong();
}
else if (cmdObj["secs"].isNumber()) {
millis = cmdObj["secs"].numberLong() * 1000;
}
else if (cmdObj["millis"].isNumber()) {
millis = cmdObj["millis"].numberLong();
}
if(cmdObj.getBoolField("w")) {
Lock::GlobalWrite lk;
sleepmillis(millis);
}
else {
Lock::GlobalRead lk;
sleepmillis(millis);
}
// Interrupt point for testing (e.g. maxTimeMS).
killCurrentOp.checkForInterrupt();
return true;
}
示例3: run
virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
log() << "replSet replSetTest command received: " << cmdObj.toString() << rsLog;
if (!checkAuth(errmsg, result)) {
return false;
}
if( cmdObj.hasElement("forceInitialSyncFailure") ) {
replSetForceInitialSyncFailure = (unsigned) cmdObj["forceInitialSyncFailure"].Number();
return true;
}
if( !check(errmsg, result) )
return false;
if( cmdObj.hasElement("blind") ) {
replSetBlind = cmdObj.getBoolField("blind");
return true;
}
if (cmdObj.hasElement("sethbmsg")) {
replset::sethbmsg(cmdObj["sethbmsg"].String());
return true;
}
return false;
}
示例4: run
bool run(OperationContext* txn, const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
log() << "test only command sleep invoked" << endl;
long long millis = 10 * 1000;
if (cmdObj["secs"].isNumber() && cmdObj["millis"].isNumber()) {
millis = cmdObj["secs"].numberLong() * 1000 + cmdObj["millis"].numberLong();
}
else if (cmdObj["secs"].isNumber()) {
millis = cmdObj["secs"].numberLong() * 1000;
}
else if (cmdObj["millis"].isNumber()) {
millis = cmdObj["millis"].numberLong();
}
if(cmdObj.getBoolField("w")) {
ScopedTransaction transaction(txn, MODE_X);
Lock::GlobalWrite lk(txn->lockState());
sleepmillis(millis);
}
else {
ScopedTransaction transaction(txn, MODE_S);
Lock::GlobalRead lk(txn->lockState());
sleepmillis(millis);
}
// Interrupt point for testing (e.g. maxTimeMS).
txn->checkForInterrupt();
return true;
}
示例5: run
virtual bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
string coll = cmdObj[ "captrunc" ].valuestrsafe();
uassert( 13416, "captrunc must specify a collection", !coll.empty() );
NamespaceString nss( dbname, coll );
int n = cmdObj.getIntField( "n" );
bool inc = cmdObj.getBoolField( "inc" ); // inclusive range?
OldClientWriteContext ctx(txn, nss.ns() );
Collection* collection = ctx.getCollection();
massert( 13417, "captrunc collection not found or empty", collection);
RecordId end;
{
boost::scoped_ptr<PlanExecutor> exec(InternalPlanner::collectionScan(txn,
nss.ns(),
collection,
InternalPlanner::BACKWARD));
// We remove 'n' elements so the start is one past that
for( int i = 0; i < n + 1; ++i ) {
PlanExecutor::ExecState state = exec->getNext(NULL, &end);
massert( 13418, "captrunc invalid n", PlanExecutor::ADVANCED == state);
}
}
WriteUnitOfWork wuow(txn);
collection->temp_cappedTruncateAfter( txn, end, inc );
wuow.commit();
return true;
}
示例6: run
virtual bool run(OperationContext* opCtx,
const string& dbname,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
const NamespaceString fullNs = CommandHelpers::parseNsCollectionRequired(dbname, cmdObj);
if (!fullNs.isValid()) {
return CommandHelpers::appendCommandStatus(
result,
{ErrorCodes::InvalidNamespace,
str::stream() << "collection name " << fullNs.ns() << " is not valid"});
}
int n = cmdObj.getIntField("n");
bool inc = cmdObj.getBoolField("inc"); // inclusive range?
if (n <= 0) {
return CommandHelpers::appendCommandStatus(
result, {ErrorCodes::BadValue, "n must be a positive integer"});
}
// Lock the database in mode IX and lock the collection exclusively.
AutoGetCollection autoColl(opCtx, fullNs, MODE_IX, MODE_X);
Collection* collection = autoColl.getCollection();
if (!collection) {
return CommandHelpers::appendCommandStatus(
result,
{ErrorCodes::NamespaceNotFound,
str::stream() << "collection " << fullNs.ns() << " does not exist"});
}
if (!collection->isCapped()) {
return CommandHelpers::appendCommandStatus(
result, {ErrorCodes::IllegalOperation, "collection must be capped"});
}
RecordId end;
{
// Scan backwards through the collection to find the document to start truncating from.
// We will remove 'n' documents, so start truncating from the (n + 1)th document to the
// end.
auto exec = InternalPlanner::collectionScan(
opCtx, fullNs.ns(), collection, PlanExecutor::NO_YIELD, InternalPlanner::BACKWARD);
for (int i = 0; i < n + 1; ++i) {
PlanExecutor::ExecState state = exec->getNext(nullptr, &end);
if (PlanExecutor::ADVANCED != state) {
return CommandHelpers::appendCommandStatus(
result,
{ErrorCodes::IllegalOperation,
str::stream() << "invalid n, collection contains fewer than " << n
<< " documents"});
}
}
}
collection->cappedTruncateAfter(opCtx, end, inc);
return true;
}
示例7: run
bool run(OperationContext* opCtx,
const std::string& ns,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
log() << "test only command sleep invoked";
long long millis = 0;
if (cmdObj["secs"] || cmdObj["seconds"] || cmdObj["millis"]) {
uassert(51153,
"Only one of 'secs' and 'seconds' may be specified",
!(cmdObj["secs"] && cmdObj["seconds"]));
if (auto secsElem = cmdObj["secs"]) {
uassert(34344, "'secs' must be a number.", secsElem.isNumber());
millis += secsElem.numberLong() * 1000;
} else if (auto secondsElem = cmdObj["seconds"]) {
uassert(51154, "'seconds' must be a number.", secondsElem.isNumber());
millis += secondsElem.numberLong() * 1000;
}
if (auto millisElem = cmdObj["millis"]) {
uassert(34345, "'millis' must be a number.", millisElem.isNumber());
millis += millisElem.numberLong();
}
} else {
millis = 10 * 1000;
}
StringData lockTarget;
if (cmdObj["lockTarget"]) {
lockTarget = cmdObj["lockTarget"].checkAndGetStringData();
}
if (!cmdObj["lock"]) {
// Legacy implementation
if (cmdObj.getBoolField("w")) {
_sleepInLock(opCtx, millis, MODE_X, lockTarget);
} else {
_sleepInLock(opCtx, millis, MODE_S, lockTarget);
}
} else {
uassert(34346, "Only one of 'w' and 'lock' may be set.", !cmdObj["w"]);
std::string lock(cmdObj.getStringField("lock"));
if (lock == "none") {
opCtx->sleepFor(Milliseconds(millis));
} else if (lock == "w") {
_sleepInLock(opCtx, millis, MODE_X, lockTarget);
} else {
uassert(34347, "'lock' must be one of 'r', 'w', 'none'.", lock == "r");
_sleepInLock(opCtx, millis, MODE_S, lockTarget);
}
}
// Interrupt point for testing (e.g. maxTimeMS).
opCtx->checkForInterrupt();
return true;
}
示例8: run
virtual bool run(OperationContext* txn,
const string& dbname,
BSONObj& cmdObj,
int,
string& errmsg,
BSONObjBuilder& result) {
const std::string fullNs = parseNsCollectionRequired(dbname, cmdObj);
int n = cmdObj.getIntField("n");
bool inc = cmdObj.getBoolField("inc"); // inclusive range?
if (n <= 0) {
return appendCommandStatus(result,
{ErrorCodes::BadValue, "n must be a positive integer"});
}
OldClientWriteContext ctx(txn, fullNs);
Collection* collection = ctx.getCollection();
if (!collection) {
return appendCommandStatus(
result,
{ErrorCodes::NamespaceNotFound,
str::stream() << "collection " << fullNs << " does not exist"});
}
if (!collection->isCapped()) {
return appendCommandStatus(result,
{ErrorCodes::IllegalOperation, "collection must be capped"});
}
RecordId end;
{
// Scan backwards through the collection to find the document to start truncating from.
// We will remove 'n' documents, so start truncating from the (n + 1)th document to the
// end.
std::unique_ptr<PlanExecutor> exec(InternalPlanner::collectionScan(
txn, fullNs, collection, PlanExecutor::YIELD_MANUAL, InternalPlanner::BACKWARD));
for (int i = 0; i < n + 1; ++i) {
PlanExecutor::ExecState state = exec->getNext(nullptr, &end);
if (PlanExecutor::ADVANCED != state) {
return appendCommandStatus(result,
{ErrorCodes::IllegalOperation,
str::stream()
<< "invalid n, collection contains fewer than "
<< n << " documents"});
}
}
}
collection->temp_cappedTruncateAfter(txn, end, inc);
return true;
}
示例9: run
void run(){
int secsToSleep = 0;
while ( 1 ){
try {
ScopedDbConnection conn( _addr );
BSONObj result;
{
BSONObjBuilder cmd;
cmd.appendOID( "writebacklisten" , &serverID );
if ( ! conn->runCommand( "admin" , cmd.obj() , result ) ){
log() << "writebacklisten command failed! " << result << endl;
conn.done();
continue;
}
}
log(1) << "writebacklisten result: " << result << endl;
BSONObj data = result.getObjectField( "data" );
if ( data.getBoolField( "writeBack" ) ){
string ns = data["ns"].valuestrsafe();
int len;
Message m( (void*)data["msg"].binData( len ) , false );
massert( 10427 , "invalid writeback message" , m.header()->valid() );
grid.getDBConfig( ns )->getChunkManager( ns , true );
Request r( m , 0 );
r.process();
}
else {
log() << "unknown writeBack result: " << result << endl;
}
conn.done();
secsToSleep = 0;
}
catch ( std::exception e ){
log() << "WriteBackListener exception : " << e.what() << endl;
}
catch ( ... ){
log() << "WriteBackListener uncaught exception!" << endl;
}
secsToSleep++;
sleepsecs(secsToSleep);
if ( secsToSleep > 10 )
secsToSleep = 0;
}
}
示例10: checkShardVersion
void checkShardVersion( DBClientBase& conn , const string& ns , bool authoritative ){
// TODO: cache, optimize, etc...
WriteBackListener::init( conn );
DBConfigPtr conf = grid.getDBConfig( ns );
if ( ! conf )
return;
ShardChunkVersion version = 0;
unsigned long long officialSequenceNumber = 0;
ChunkManagerPtr manager;
const bool isSharded = conf->isSharded( ns );
if ( isSharded ){
manager = conf->getChunkManager( ns , authoritative );
officialSequenceNumber = manager->getSequenceNumber();
}
unsigned long long & sequenceNumber = checkShardVersionLastSequence[ make_pair(&conn,ns) ];
if ( sequenceNumber == officialSequenceNumber )
return;
if ( isSharded ){
version = manager->getVersion( Shard::make( conn.getServerAddress() ) );
}
log(2) << " have to set shard version for conn: " << &conn << " ns:" << ns
<< " my last seq: " << sequenceNumber << " current: " << officialSequenceNumber
<< " version: " << version << " manager: " << manager.get()
<< endl;
BSONObj result;
if ( setShardVersion( conn , ns , version , authoritative , result ) ){
// success!
log(1) << " setShardVersion success!" << endl;
sequenceNumber = officialSequenceNumber;
dassert( sequenceNumber == checkShardVersionLastSequence[ make_pair(&conn,ns) ] );
return;
}
log(1) << " setShardVersion failed!\n" << result << endl;
if ( result.getBoolField( "need_authoritative" ) )
massert( 10428 , "need_authoritative set but in authoritative mode already" , ! authoritative );
if ( ! authoritative ){
checkShardVersion( conn , ns , 1 );
return;
}
log() << " setShardVersion failed: " << result << endl;
massert( 10429 , (string)"setShardVersion failed! " + result.jsonString() , 0 );
}
示例11: execCommandClientBasic
void Command::execCommandClientBasic(OperationContext* txn,
Command* c,
ClientBasic& client,
int queryOptions,
const char* ns,
BSONObj& cmdObj,
BSONObjBuilder& result) {
std::string dbname = nsToDatabase(ns);
if (cmdObj.getBoolField("help")) {
stringstream help;
help << "help for: " << c->name << " ";
c->help(help);
result.append("help", help.str());
result.append("lockType", c->isWriteCommandForConfigServer() ? 1 : 0);
appendCommandStatus(result, true, "");
return;
}
Status status = _checkAuthorization(c, &client, dbname, cmdObj);
if (!status.isOK()) {
appendCommandStatus(result, status);
return;
}
c->_commandsExecuted.increment();
if (c->shouldAffectCommandCounter()) {
globalOpCounters.gotCommand();
}
std::string errmsg;
bool ok = false;
try {
ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
} catch (const DBException& e) {
const int code = e.getCode();
// Codes for StaleConfigException
if (code == RecvStaleConfigCode || code == SendStaleConfigCode) {
throw;
}
errmsg = e.what();
result.append("code", code);
}
if (!ok) {
c->_commandsFailed.increment();
}
appendCommandStatus(result, ok, errmsg);
}
示例12: runAgainstRegistered
bool Command::runAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder& anObjBuilder) {
const char *p = strchr(ns, '.');
if ( !p ) return false;
if ( strcmp(p, ".$cmd") != 0 ) return false;
bool ok = false;
bool valid = false;
BSONElement e;
e = jsobj.firstElement();
map<string,Command*>::iterator i;
if ( e.eoo() )
;
/* check for properly registered command objects. Note that all the commands below should be
migrated over to the command object format.
*/
else if ( (i = _commands->find(e.fieldName())) != _commands->end() ) {
valid = true;
string errmsg;
Command *c = i->second;
if ( c->adminOnly() && strncmp(ns, "admin", 5) != 0 ) {
ok = false;
errmsg = "access denied";
}
else if ( jsobj.getBoolField( "help" ) ){
stringstream help;
help << "help for: " << e.fieldName() << " ";
c->help( help );
anObjBuilder.append( "help" , help.str() );
}
else {
ok = c->run(ns, jsobj, errmsg, anObjBuilder, false);
}
BSONObj tmp = anObjBuilder.asTempObj();
bool have_ok = tmp.hasField("ok");
bool have_errmsg = tmp.hasField("errmsg");
if (!have_ok)
anObjBuilder.append( "ok" , ok ? 1.0 : 0.0 );
if ( !ok && !have_errmsg) {
anObjBuilder.append("errmsg", errmsg);
uassert_nothrow(errmsg.c_str());
}
return true;
}
return false;
}
示例13: unserialize
void DBConfig::unserialize(const BSONObj& from) {
log(1) << "DBConfig unserialize: " << _name << " " << from << endl;
assert( _name == from["_id"].String() );
_shardingEnabled = from.getBoolField("partitioned");
_primary.reset( from.getStringField("primary") );
// In the 1.5.x series, we used to have collection metadata nested in the database entry. The 1.6.x series
// had migration code that ported that info to where it belongs now: the 'collections' collection. We now
// just assert that we're not migrating from a 1.5.x directly into a 1.7.x without first converting.
BSONObj sharded = from.getObjectField( "sharded" );
if ( ! sharded.isEmpty() )
uasserted( 13509 , "can't migrate from 1.5.x release to the current one; need to upgrade to 1.6.x first");
}
示例14: unserialize
void DBConfig::unserialize(const BSONObj& from){
_name = from.getStringField("name");
_partitioned = from.getBoolField("partitioned");
_primary = from.getStringField("primary");
_sharded.clear();
BSONObj sharded = from.getObjectField( "sharded" );
if ( ! sharded.isEmpty() ){
BSONObjIterator i(sharded);
while ( i.more() ){
BSONElement e = i.next();
uassert( "sharded things have to be objects" , e.type() == Object );
_sharded[e.fieldName()] = e.embeddedObject();
}
}
}
示例15: execCommandClientBasic
void Command::execCommandClientBasic(OperationContext* txn,
Command * c ,
ClientBasic& client,
int queryOptions,
const char *ns,
BSONObj& cmdObj,
BSONObjBuilder& result,
bool fromRepl ) {
std::string dbname = nsToDatabase(ns);
if (cmdObj.getBoolField("help")) {
stringstream help;
help << "help for: " << c->name << " ";
c->help( help );
result.append( "help" , help.str() );
result.append("lockType", c->isWriteCommandForConfigServer() ? 1 : 0);
appendCommandStatus(result, true, "");
return;
}
Status status = _checkAuthorization(c, &client, dbname, cmdObj, fromRepl);
if (!status.isOK()) {
appendCommandStatus(result, status);
return;
}
std::string errmsg;
bool ok;
try {
ok = c->run( txn, dbname , cmdObj, queryOptions, errmsg, result, false );
}
catch (DBException& e) {
ok = false;
int code = e.getCode();
if (code == RecvStaleConfigCode) { // code for StaleConfigException
throw;
}
stringstream ss;
ss << "exception: " << e.what();
errmsg = ss.str();
result.append( "code" , code );
}
appendCommandStatus(result, ok, errmsg);
}