当前位置: 首页>>代码示例>>C++>>正文


C++ BSONObj::hasElement方法代码示例

本文整理汇总了C++中BSONObj::hasElement方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::hasElement方法的具体用法?C++ BSONObj::hasElement怎么用?C++ BSONObj::hasElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BSONObj的用法示例。


在下文中一共展示了BSONObj::hasElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rollbackTransactionFromOplog

 void rollbackTransactionFromOplog(BSONObj entry, bool purgeEntry) {
     bool transactionAlreadyApplied = entry["a"].Bool();
     Client::Transaction transaction(DB_SERIALIZABLE);
     if (transactionAlreadyApplied) {
         if (entry.hasElement("ref")) {
             rollbackRefOp(entry);
         } else if (entry.hasElement("ops")) {
             rollbackOps(entry["ops"].Array());
         } else {
             verify(0);
         }
     }
     {
         LOCK_REASON(lockReason, "repl: purging entry from oplog");
         Lock::DBRead lk1("local", lockReason);
         if (purgeEntry) {
             purgeEntryFromOplog(entry);
         }
         else {
             // set the applied bool to false, to let the oplog know that
             // this entry has not been applied to collections
             BSONElementManipulator(entry["a"]).setBool(false);
             writeEntryToOplog(entry, false);
         }
     }
     transaction.commit(DB_TXN_NOSYNC);
 }
开发者ID:nvdnkpr,项目名称:mongo,代码行数:27,代码来源:oplog.cpp

示例2: run

        bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
            bool all = *cmdObj.firstElement().valuestrsafe() == '*';

            int before = result.len();

            // TODO: convert to ServerParameters -- SERVER-10515

            if (isJournalingEnabled() && (all || cmdObj.hasElement("journalCommitInterval")) &&
                !isMongos()) {
                result.append("journalCommitInterval",
                              getJournalCommitInterval());
            }
            if( all || cmdObj.hasElement( "traceExceptions" ) ) {
                result.append("traceExceptions",
                              DBException::traceExceptions);
            }
            if( all || cmdObj.hasElement( "replMonitorMaxFailedChecks" ) ) {
                result.append("replMonitorMaxFailedChecks",
                              ReplicaSetMonitor::getMaxFailedChecks());
            }

            const ServerParameter::Map& m = ServerParameterSet::getGlobal()->getMap();
            for ( ServerParameter::Map::const_iterator i = m.begin(); i != m.end(); ++i ) {
                if ( all || cmdObj.hasElement( i->first.c_str() ) ) {
                    i->second->append( result, i->second->name() );
                }
            }

            if ( before == result.len() ) {
                errmsg = "no option found to get";
                return false;
            }
            return true;
        }
开发者ID:ChrisKozak,项目名称:mongo,代码行数:34,代码来源:parameters.cpp

示例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;
        }
开发者ID:criticus,项目名称:mongo,代码行数:27,代码来源:replset_commands.cpp

示例4: applyTransactionFromOplog

 // takes an entry that was written _logTransactionOps
 // and applies them to collections
 //
 // TODO: possibly improve performance of this. We create and destroy a
 // context for each operation. Find a way to amortize it out if necessary
 //
 void applyTransactionFromOplog(BSONObj entry) {
     bool transactionAlreadyApplied = entry["a"].Bool();
     if (!transactionAlreadyApplied) {
         Client::Transaction transaction(DB_SERIALIZABLE);
         if (entry.hasElement("ref")) {
             applyRefOp(entry);
         } else if (entry.hasElement("ops")) {
             applyOps(entry["ops"].Array());
         } else {
             verify(0);
         }
         // set the applied bool to true, to let the oplog know that
         // this entry has been applied to collections
         BSONElementManipulator(entry["a"]).setBool(true);
         {
             LOCK_REASON(lockReason, "repl: setting oplog entry's applied bit");
             Lock::DBRead lk1("local", lockReason);
             writeEntryToOplog(entry, false);
         }
         // If this code fails, it is impossible to recover from
         // because we don't know if the transaction successfully committed
         // so we might as well crash
         // There is currently no known way this code can throw an exception
         try {
             // we are operating as a secondary. We don't have to fsync
             transaction.commit(DB_TXN_NOSYNC);
         }
         catch (std::exception &e) {
             log() << "exception during commit of applyTransactionFromOplog, aborting system: " << e.what() << endl;
             printStackTrace();
             logflush();
             ::abort();
         }
     }
 }
开发者ID:nvdnkpr,项目名称:mongo,代码行数:41,代码来源:oplog.cpp

示例5: run

        bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
            bool all = *cmdObj.firstElement().valuestrsafe() == '*';
            
            int before = result.len();
            
            if( all || cmdObj.hasElement("quiet") ) {
                result.append("quiet", cmdLine.quiet );
            }
            if( all || cmdObj.hasElement("notablescan") ) {
                result.append("notablescan", cmdLine.noTableScan);
            }
            if( all || cmdObj.hasElement("logLevel") ) {
                result.append("logLevel", logLevel);
            }
            if( all || cmdObj.hasElement("syncdelay") ) {
                result.append("syncdelay", cmdLine.syncdelay);
            }
            if( all || cmdObj.hasElement("replApplyBatchSize") ) {
                result.append("replApplyBatchSize", replApplyBatchSize);
            }           

            if ( before == result.len() ) {
                errmsg = "no option found to get";
                return false;
            }
            return true;
        }
开发者ID:ALFIO,项目名称:mongo,代码行数:27,代码来源:dbcommands_generic.cpp

示例6: parseOutputOptions

        Config::OutputOptions Config::parseOutputOptions(const std::string& dbname,
                                                         const BSONObj& cmdObj) {
            Config::OutputOptions outputOptions;

            outputOptions.outNonAtomic = false;
            if (cmdObj["out"].type() == String) {
                outputOptions.collectionName = cmdObj["out"].String();
                outputOptions.outType = REPLACE;
            }
            else if (cmdObj["out"].type() == Object) {
                BSONObj o = cmdObj["out"].embeddedObject();

                BSONElement e = o.firstElement();
                string t = e.fieldName();

                if (t == "normal" || t == "replace") {
                    outputOptions.outType = REPLACE;
                    outputOptions.collectionName = e.String();
                }
                else if (t == "merge") {
                    outputOptions.outType = MERGE;
                    outputOptions.collectionName = e.String();
                }
                else if (t == "reduce") {
                    outputOptions.outType = REDUCE;
                    outputOptions.collectionName = e.String();
                }
                else if (t == "inline") {
                    outputOptions.outType = INMEMORY;
                }
                else {
                    uasserted(13522,
                              mongoutils::str::stream() << "unknown out specifier [" << t << "]");
                }

                if (o.hasElement("db")) {
                    outputOptions.outDB = o["db"].String();
                }

                if (o.hasElement("nonAtomic")) {
                    outputOptions.outNonAtomic = o["nonAtomic"].Bool();
                    if (outputOptions.outNonAtomic)
                        uassert(15895,
                                "nonAtomic option cannot be used with this output type",
                                (outputOptions.outType == REDUCE ||
                                         outputOptions.outType == MERGE));
                }
            }
            else {
                uasserted(13606 , "'out' has to be a string or an object");
            }

            if (outputOptions.outType != INMEMORY) {
                outputOptions.finalNamespace = mongoutils::str::stream()
                    << (outputOptions.outDB.empty() ? dbname : outputOptions.outDB)
                    << "." << outputOptions.collectionName;
            }

            return outputOptions;
        }
开发者ID:10genReviews,项目名称:mongo,代码行数:60,代码来源:mr_common.cpp

示例7: run

        virtual bool run(const string& db, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
            string coll = cmdObj.firstElement().valuestr();
            if( coll.empty() || db.empty() ) {
                errmsg = "no collection name specified";
                return false;
            }

            if( isCurrentlyAReplSetPrimary() && !cmdObj["force"].trueValue() ) { 
                errmsg = "will not run compact on an active replica set primary as this is a slow blocking operation. use force:true to force";
                return false;
            }
            
            string ns = db + '.' + coll;
            if ( ! NamespaceString::normal(ns.c_str()) ) {
                errmsg = "bad namespace name";
                return false;
            }
            
            // parameter validation to avoid triggering assertions in compact()
            if ( str::contains(ns, ".system.") ) {
                errmsg = "can't compact a system namespace";
                return false;
            }
            
            {
                writelock lk;
                Client::Context ctx(ns);
                NamespaceDetails *d = nsdetails(ns.c_str());
                if( ! d ) {
                    errmsg = "namespace does not exist";
                    return false;
                }

                if ( d->capped ) {
                    errmsg = "cannot compact a capped collection";
                    return false;
                }
            }

            double pf = 1.0;
            int pb = 0;
            if( cmdObj.hasElement("paddingFactor") ) {
                pf = cmdObj["paddingFactor"].Number();
                assert( pf >= 1.0 && pf <= 4.0 );
            }
            if( cmdObj.hasElement("paddingBytes") ) {
                pb = (int) cmdObj["paddingBytes"].Number();
                assert( pb >= 0 && pb <= 1024 * 1024 );
            }

            bool validate = !cmdObj.hasElement("validate") || cmdObj["validate"].trueValue(); // default is true at the moment
            bool ok = compact(ns, errmsg, validate, result, pf, pb);
            return ok;
        }
开发者ID:adi2188,项目名称:mongo,代码行数:54,代码来源:compact.cpp

示例8: up

        void up(const BSONObj& info, HeartbeatInfo& mem) {
            HeartbeatInfo::numPings++;
            mem.authIssue = false;

            if( mem.upSince == 0 ) {
                log() << "replSet member " << h.toString() << " is up" << rsLog;
                mem.upSince = mem.lastHeartbeat;
            }
            mem.health = 1.0;
            mem.lastHeartbeatMsg = info["hbmsg"].String();
            if (info.hasElement("syncingTo")) {
                mem.syncingTo = info["syncingTo"].String();
            }

            if( info.hasElement("opTime") )
                mem.opTime = info["opTime"].Date();

            // see if this member is in the electable set
            if( info["e"].eoo() ) {
                // for backwards compatibility
                const Member *member = theReplSet->findById(mem.id());
                if (member && member->config().potentiallyHot()) {
                    theReplSet->addToElectable(mem.id());
                }
                else {
                    theReplSet->rmFromElectable(mem.id());
                }
            }
            // add this server to the electable set if it is within 10
            // seconds of the latest optime we know of
            else if( info["e"].trueValue() &&
                     mem.opTime >= theReplSet->lastOpTimeWritten.getSecs() - 10) {
                unsigned lastOp = theReplSet->lastOtherOpTime().getSecs();
                if (lastOp > 0 && mem.opTime >= lastOp - 10) {
                    theReplSet->addToElectable(mem.id());
                }
            }
            else {
                theReplSet->rmFromElectable(mem.id());
            }

            be cfg = info["config"];
            if( cfg.ok() ) {
                // received a new config
                boost::function<void()> f =
                    boost::bind(&Manager::msgReceivedNewConfig, theReplSet->mgr, cfg.Obj().copy());
                theReplSet->mgr->send(f);
            }
        }
开发者ID:Faleij,项目名称:mongo-arm,代码行数:49,代码来源:heartbeat.cpp

示例9: isComplex

bool Query::isComplex(const BSONObj& obj, bool* hasDollar) {
    if (obj.hasElement("query")) {
        if (hasDollar)
            *hasDollar = false;
        return true;
    }

    if (obj.hasElement("$query")) {
        if (hasDollar)
            *hasDollar = true;
        return true;
    }

    return false;
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:15,代码来源:query.cpp

示例10: run

    virtual bool run(const string& , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
        log() << "replSet replSetTest command received: " << cmdObj.toString() << rsLog;
        if( cmdObj.hasElement("forceInitialSyncFailure") ) {
            replSetForceInitialSyncFailure = (unsigned) cmdObj["forceInitialSyncFailure"].Number();
            return true;
        }

        // may not need this, but if removed check all tests still work:
        if( !check(errmsg, result) )
            return false;

        if( cmdObj.hasElement("blind") ) {
            replSetBlind = cmdObj.getBoolField("blind");
            return true;
        }
        return false;
    }
开发者ID:rauchg,项目名称:mongo,代码行数:17,代码来源:replset_commands.cpp

示例11: errmsgRun

    virtual bool errmsgRun(OperationContext* opCtx,
                           const string& db,
                           const BSONObj& cmdObj,
                           string& errmsg,
                           BSONObjBuilder& result) {
        NamespaceString nss = CommandHelpers::parseNsCollectionRequired(db, cmdObj);

        repl::ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(opCtx);
        if (replCoord->getMemberState().primary() && !cmdObj["force"].trueValue()) {
            errmsg =
                "will not run compact on an active replica set primary as this is a slow blocking "
                "operation. use force:true to force";
            return false;
        }

        if (!nss.isNormal()) {
            errmsg = "bad namespace name";
            return false;
        }

        if (nss.isSystem()) {
            // Items in system.* cannot be moved as there might be pointers to them.
            errmsg = "can't compact a system namespace";
            return false;
        }

        CompactOptions compactOptions;

        if (cmdObj.hasElement("validate"))
            compactOptions.validateDocuments = cmdObj["validate"].trueValue();

        AutoGetDb autoDb(opCtx, db, MODE_X);
        Database* const collDB = autoDb.getDb();

        Collection* collection = collDB ? collDB->getCollection(opCtx, nss) : nullptr;
        auto view =
            collDB && !collection ? ViewCatalog::get(collDB)->lookup(opCtx, nss.ns()) : nullptr;

        // If db/collection does not exist, short circuit and return.
        if (!collDB || !collection) {
            if (view)
                uasserted(ErrorCodes::CommandNotSupportedOnView, "can't compact a view");
            else
                uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist");
        }

        OldClientContext ctx(opCtx, nss.ns());
        BackgroundOperation::assertNoBgOpInProgForNs(nss.ns());

        log() << "compact " << nss.ns() << " begin, options: " << compactOptions;

        StatusWith<CompactStats> status = compactCollection(opCtx, collection, &compactOptions);
        uassertStatusOK(status.getStatus());

        log() << "compact " << nss.ns() << " end";

        return true;
    }
开发者ID:visualzhou,项目名称:mongo,代码行数:58,代码来源:compact.cpp

示例12: replicateFullTransactionToOplog

    void replicateFullTransactionToOplog(BSONObj& o, OplogReader& r, bool* bigTxn) {
        *bigTxn = false;
        if (o.hasElement("ref")) {
            OID oid = o["ref"].OID();
            LOG(3) << "oplog ref " << oid << endl;
            copyOplogRefsRange(r, oid);
            *bigTxn = true;
        }

        Client::ReadContext ctx(rsoplog);
        replicateTransactionToOplog(o);
    }
开发者ID:aberg001,项目名称:mongo,代码行数:12,代码来源:oplog.cpp

示例13: run

        bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
            int s = 0;
            bool found = setParmsMongodSpecific(dbname, cmdObj, errmsg, result, fromRepl);
            if( cmdObj.hasElement("journalCommitInterval") ) { 
                if( !cmdLine.dur ) { 
                    errmsg = "journaling is off";
                    return false;
                }
                int x = (int) cmdObj["journalCommitInterval"].Number();
                assert( x > 1 && x < 500 );
                cmdLine.journalCommitInterval = x;
                log() << "setParameter journalCommitInterval=" << x << endl;
                s++;
            }
            if( cmdObj.hasElement("notablescan") ) {
                assert( !cmdLine.isMongos() );
                if( s == 0 )
                    result.append("was", cmdLine.noTableScan);
                cmdLine.noTableScan = cmdObj["notablescan"].Bool();
                s++;
            }
            if( cmdObj.hasElement("quiet") ) {
                if( s == 0 )
                    result.append("was", cmdLine.quiet );
                cmdLine.quiet = cmdObj["quiet"].Bool();
                s++;
            }
            if( cmdObj.hasElement("syncdelay") ) {
                assert( !cmdLine.isMongos() );
                if( s == 0 )
                    result.append("was", cmdLine.syncdelay );
                cmdLine.syncdelay = cmdObj["syncdelay"].Number();
                s++;
            }
            if( cmdObj.hasElement( "logLevel" ) ) {
                if( s == 0 )
                    result.append("was", logLevel );
                logLevel = cmdObj["logLevel"].numberInt();
                s++;
            }
            if( cmdObj.hasElement( "replApplyBatchSize" ) ) {
                if( s == 0 )
                    result.append("was", replApplyBatchSize );
                BSONElement e = cmdObj["replApplyBatchSize"];
                ParameterValidator * v = ParameterValidator::get( e.fieldName() );
                assert( v );
                if ( ! v->isValid( e , errmsg ) )
                    return false;
                replApplyBatchSize = e.numberInt();
                s++;
            }

            if( s == 0 && !found ) {
                errmsg = "no option found to set, use help:true to see options ";
                return false;
            }

            return true;
        }
开发者ID:Eisforinnovate,项目名称:mongo,代码行数:59,代码来源:dbcommands_generic.cpp

示例14: replicateFullTransactionToOplog

    void replicateFullTransactionToOplog(BSONObj& o, OplogReader& r, bool* bigTxn) {
        *bigTxn = false;
        if (o.hasElement("ref")) {
            OID oid = o["ref"].OID();
            LOG(3) << "oplog ref " << oid << endl;
            copyOplogRefsRange(r, oid);
            *bigTxn = true;
        }

        LOCK_REASON(lockReason, "repl: copying entry to local oplog");
        Client::ReadContext ctx(rsoplog, lockReason);
        replicateTransactionToOplog(o);
    }
开发者ID:nvdnkpr,项目名称:mongo,代码行数:13,代码来源:oplog.cpp

示例15: readFromDB

/**********************************************************
 *reads from db and converts bson to FileRec object
 * 
***********************************************************/
void FileRec::readFromDB(mongo::DBClientConnection& conn, string filename) {

    boost::filesystem::path p(filename); //get filename from path
    string file(p.filename().c_str());
    auto_ptr<mongo::DBClientCursor> cursor = conn.query("fileRecords.Filerec", MONGO_QUERY("filename" << file));

    if (cursor->more()) {

        BSONObj record = cursor->next();
        //get data from db and store in the FileRec
        this->filename = record.getStringField("filename");
        this->tempname = record.getStringField("Tempname");
        this->recentHash = record.getStringField("curhash");
        this->origHash = record.getStringField("ovhash");
        this->length = record.getIntField("length");
        this->versionCount = record.getIntField("nversions");
        this->modifytime.tv_nsec = record.getField("Mtnsec").numberLong();
        this->modifytime.tv_sec = record.getField("mtsec").numberLong();
        this->refNum = record.getIntField("currentversion");

        vector<BSONElement> hashes(record.getField("FileBlkHashes").Array());
        for (vector<BSONElement>::iterator it = hashes.begin(); it != hashes.end(); ++it) {
            appendBlock((*it).String());
        }

        //comments is an array of objects so it takes a bit of nesting to convert
        vector<BSONElement> array = record["comments"].Array(); //convert to array
        for (vector<BSONElement>::iterator ar = array.begin(); ar != array.end(); ++ar) {
            BSONObj commentdata = ar->Obj(); //store object at array[x] into BSONObj
            BSONElement version = commentdata.getField("version"); //convert
            BSONElement commentdb = commentdata.getField("comment");

            comment data;
            data.comment = commentdb.String();
            data.version = version.Int();
            appendComment(data);
        }


        if (record.hasElement("versionrec")) { //again an array of objects
            vector<BSONElement> array = record["versionrec"].Array();
            for (vector<BSONElement>::iterator it = array.begin(); it != array.end(); ++it) {

                BSONObj versionRecord = it->Obj();
                BSONElement id = versionRecord.getField("id");
                appendVersion(id.String());
            }
        } 
    }
}
开发者ID:matthewschwarze,项目名称:csci222,代码行数:54,代码来源:FileRec.cpp


注:本文中的BSONObj::hasElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。