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


C++ BSONObjBuilder::appendBool方法代码示例

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


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

示例1: setShardVersion

    bool setShardVersion(DBClientBase& conn,
                         const string& ns,
                         const string& configServerPrimary,
                         ChunkVersion version,
                         ChunkManager* manager,
                         bool authoritative,
                         BSONObj& result) {

        BSONObjBuilder cmdBuilder;
        cmdBuilder.append("setShardVersion", ns);
        cmdBuilder.append("configdb", configServerPrimary);

        Shard s = Shard::make(conn.getServerAddress());
        cmdBuilder.append("shard", s.getName());
        cmdBuilder.append("shardHost", s.getConnString());

        if (ns.size() > 0) {
            version.addToBSON(cmdBuilder);
        }
        else {
            cmdBuilder.append("init", true);
        }

        if (authoritative) {
            cmdBuilder.appendBool("authoritative", 1);
        }

        BSONObj cmd = cmdBuilder.obj();

        LOG(1) << "    setShardVersion  " << s.getName() << " " << conn.getServerAddress()
               << "  " << ns << "  " << cmd
               << (manager ? string(str::stream() << " " << manager->getSequenceNumber()) : "");

        return conn.runCommand("admin", cmd, result, 0);
    }
开发者ID:ForNowForever,项目名称:mongo,代码行数:35,代码来源:shard_connection.cpp

示例2: appendSelf

bool LastError::appendSelf(BSONObjBuilder& b, bool blankErr) const {
    if (!_valid) {
        if (blankErr)
            b.appendNull("err");
        b.append("n", 0);
        return false;
    }

    if (_msg.empty()) {
        if (blankErr) {
            b.appendNull("err");
        }
    } else {
        b.append("err", _msg);
    }

    if (_code) {
        b.append("code", _code);
        b.append("codeName", ErrorCodes::errorString(ErrorCodes::Error(_code)));
    }
    if (_updatedExisting != NotUpdate)
        b.appendBool("updatedExisting", _updatedExisting == True);
    if (!_upsertedId.isEmpty()) {
        b.append(_upsertedId[kUpsertedFieldName]);
    }
    b.appendNumber("n", _nObjects);

    return !_msg.empty();
}
开发者ID:i80and,项目名称:mongo,代码行数:29,代码来源:lasterror.cpp

示例3: run

 bool run(const string& dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
     result << "version" << versionString << "gitVersion" << gitVersion() << "sysInfo" << sysInfo();
     result << "bits" << ( sizeof( int* ) == 4 ? 32 : 64 );
     result.appendBool( "debug" , debug );
     result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
     return true;
 }
开发者ID:BendustiK,项目名称:mongo,代码行数:7,代码来源:dbcommands_generic.cpp

示例4: ensureIndex

    bool DBClientWithCommands::ensureIndex( const string &ns , BSONObj keys , bool unique, const string & name ) {
        BSONObjBuilder toSave;
        toSave.append( "ns" , ns );
        toSave.append( "key" , keys );

        string cacheKey(ns);
        cacheKey += "--";

        if ( name != "" ) {
            toSave.append( "name" , name );
            cacheKey += name;
        }
        else {
            string nn = genIndexName( keys );
            toSave.append( "name" , nn );
            cacheKey += nn;
        }
        
        if ( unique )
            toSave.appendBool( "unique", unique );

        if ( _seenIndexes.count( cacheKey ) )
            return 0;
        _seenIndexes.insert( cacheKey );

        insert( Namespace( ns.c_str() ).getSisterNS( "system.indexes"  ).c_str() , toSave.obj() );
        return 1;
    }
开发者ID:mikejs,项目名称:mongo,代码行数:28,代码来源:dbclient.cpp

示例5: listFiles

 BSONObj listFiles(const BSONObj& args){
     uassert( "need to specify 1 argument to listFiles" , args.nFields() == 1 );
     
     BSONObjBuilder lst;
     
     string rootname = args.firstElement().valuestrsafe();
     path root( rootname );
     
     directory_iterator end;
     directory_iterator i( root);
     
     int num =0;
     while ( i != end ){
         path p = *i;
         
         BSONObjBuilder b;
         b << "name" << p.string();
         b.appendBool( "isDirectory", is_directory( p ) );
         stringstream ss;
         ss << num;
         string name = ss.str();
         lst.append( name.c_str(), b.done() );
         
         num++;
         i++;
     }
     
     BSONObjBuilder ret;
     ret.appendArray( "", lst.done() );
     return ret.obj();
 }
开发者ID:alanw,项目名称:mongo,代码行数:31,代码来源:utils.cpp

示例6: checkConfigOrInit

        bool checkConfigOrInit( const string& configdb , bool authoritative , string& errmsg , BSONObjBuilder& result , bool locked=false ) const {
            if ( configdb.size() == 0 ) {
                errmsg = "no configdb";
                return false;
            }
            
            if ( shardingState.enabled() ) {
                if ( configdb == shardingState.getConfigServer() ) 
                    return true;
                
                result.append( "configdb" , BSON( "stored" << shardingState.getConfigServer() << 
                                                  "given" << configdb ) );
                errmsg = "specified a different configdb!";
                return false;
            }
            
            if ( ! authoritative ) {
                result.appendBool( "need_authoritative" , true );
                errmsg = "first setShardVersion";
                return false;
            }
            
            if ( locked ) {
                shardingState.enable( configdb );
                configServer.init( configdb );
                return true;
            }

            dblock lk;
            return checkConfigOrInit( configdb , authoritative , errmsg , result , true );
        }
开发者ID:chorfa672m,项目名称:mongo,代码行数:31,代码来源:d_state.cpp

示例7: Timestamp

void KVCatalog::FeatureTracker::putInfo(OperationContext* opCtx, const FeatureBits& versionInfo) {
    BSONObjBuilder bob;
    bob.appendBool(kIsFeatureDocumentFieldName, true);
    // We intentionally include the "ns" field with a null value in the feature document to prevent
    // older versions that do 'obj["ns"].String()' from starting up. This way only versions that are
    // aware of the feature document's existence can successfully start up.
    bob.appendNull(kNamespaceFieldName);
    bob.append(kNonRepairableFeaturesFieldName,
               static_cast<long long>(versionInfo.nonRepairableFeatures));
    bob.append(kRepairableFeaturesFieldName,
               static_cast<long long>(versionInfo.repairableFeatures));
    BSONObj obj = bob.done();

    if (_rid.isNull()) {
        // This is the first time a feature is being marked as in-use or not in-use, so we must
        // insert the feature document rather than update it.
        const bool enforceQuota = false;
        // TODO SERVER-30638: using timestamp 0 for these inserts
        auto rid = _catalog->_rs->insertRecord(
            opCtx, obj.objdata(), obj.objsize(), Timestamp(), enforceQuota);
        fassert(40113, rid.getStatus());
        _rid = rid.getValue();
    } else {
        const bool enforceQuota = false;
        UpdateNotifier* notifier = nullptr;
        auto status = _catalog->_rs->updateRecord(
            opCtx, _rid, obj.objdata(), obj.objsize(), enforceQuota, notifier);
        fassert(40114, status);
    }
}
开发者ID:zhihuiFan,项目名称:mongo,代码行数:30,代码来源:kv_catalog.cpp

示例8: run

        bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {

            BSONElement e = cmdObj.firstElement();
            if ( e.type() != jstOID ) {
                errmsg = "need oid as first value";
                return 0;
            }

            // get the command issuer's (a mongos) serverID
            const OID id = e.__oid();

            // the command issuer is blocked awaiting a response
            // we want to do return at least at every 5 minutes so sockets don't timeout
            BSONObj z;
            if ( writeBackManager.getWritebackQueue(id.str())->queue.blockingPop( z, 5 * 60 /* 5 minutes */ ) ) {
                MONGO_LOG(1) << "WriteBackCommand got : " << z << endl;
                result.append( "data" , z );
            }
            else {
                result.appendBool( "noop" , true );
            }

#ifdef _DEBUG
            // Sleep a short amount of time usually
            int sleepFor = rand() % 10;
            sleepmillis( sleepFor );

            // Sleep a longer amount of time every once and awhile
            int sleepLong = rand() % 50;
            if( sleepLong == 0 ) sleepsecs( 2 );
#endif

            return true;
        }
开发者ID:tanakh,项目名称:mongo,代码行数:34,代码来源:d_writeback.cpp

示例9: setProfilingLevel

    bool Database::setProfilingLevel( int newLevel , string& errmsg ) {
        if ( profile == newLevel )
            return true;

        if ( newLevel < 0 || newLevel > 2 ) {
            errmsg = "profiling level has to be >=0 and <= 2";
            return false;
        }

        if ( newLevel == 0 ) {
            profile = 0;
            return true;
        }

        assert( cc().database() == this );

        if ( ! namespaceIndex.details( profileName.c_str() ) ) {
            log() << "creating profile collection: " << profileName << endl;
            BSONObjBuilder spec;
            spec.appendBool( "capped", true );
            spec.append( "size", 131072.0 );
            if ( ! userCreateNS( profileName.c_str(), spec.done(), errmsg , false /* we don't replica profile messages */ ) ) {
                return false;
            }
        }
        profile = newLevel;
        return true;
    }
开发者ID:dgriffith,项目名称:mongo,代码行数:28,代码来源:database.cpp

示例10: run

        bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
            string ns = cmdObj["getShardVersion"].valuestrsafe();
            if ( ns.size() == 0 ) {
                errmsg = "need to specify full namespace";
                return false;
            }

            result.append( "configServer" , shardingState.getConfigServer() );

            result.appendTimestamp( "global" , shardingState.getVersion(ns).toLong() );

            ShardedConnectionInfo* info = ShardedConnectionInfo::get( false );
            result.appendBool( "inShardedMode" , info != 0 );
            if ( info )
                result.appendTimestamp( "mine" , info->getVersion(ns).toLong() );
            else
                result.appendTimestamp( "mine" , 0 );

            if ( cmdObj["fullMetadata"].trueValue() ) {
                CollectionMetadataPtr metadata = shardingState.getCollectionMetadata( ns );
                if ( metadata ) result.append( "metadata", metadata->toBSON() );
                else result.append( "metadata", BSONObj() );
            }

            return true;
        }
开发者ID:GitSullied,项目名称:mongo,代码行数:26,代码来源:d_state.cpp

示例11: checkConfigOrInit

    bool checkConfigOrInit( const string& configdb , bool authoritative , string& errmsg , BSONObjBuilder& result , bool locked=false ) const {
        if ( configdb.size() == 0 ) {
            errmsg = "no configdb";
            return false;
        }

        if ( shardingState.enabled() ) {
            if ( configdb == shardingState.getConfigServer() )
                return true;

            result.append( "configdb" , BSON( "stored" << shardingState.getConfigServer() <<
                                              "given" << configdb ) );

            errmsg = str::stream() << "mongos specified a different config database string : "
                     << "stored : " << shardingState.getConfigServer()
                     << " vs given : " << configdb;
            return false;
        }

        if ( ! authoritative ) {
            result.appendBool( "need_authoritative" , true );
            errmsg = "first setShardVersion";
            return false;
        }

        if ( locked ) {
            ShardedConnectionInfo::addHook();
            shardingState.enable( configdb );
            configServer.init( configdb );
            return true;
        }

        Lock::GlobalWrite lk;
        return checkConfigOrInit( configdb , authoritative , errmsg , result , true );
    }
开发者ID:jjwchoy,项目名称:mongo,代码行数:35,代码来源:d_state.cpp

示例12: serialize

 void DBConfig::serialize(BSONObjBuilder& to){
     to.append("name", _name);
     to.appendBool("partitioned", _shardingEnabled );
     to.append("primary", _primary );
     
     if ( _sharded.size() > 0 ){
         BSONObjBuilder a;
         for ( map<string,CollectionInfo>::reverse_iterator i=_sharded.rbegin(); i != _sharded.rend(); i++){
             BSONObjBuilder temp;
             temp.append( "key" , i->second.key.key() );
             temp.appendBool( "unique" , i->second.unique );
             a.append( i->first.c_str() , temp.obj() );
         }
         to.append( "sharded" , a.obj() );
     }
 }
开发者ID:IlyaM,项目名称:mongo,代码行数:16,代码来源:config.cpp

示例13: pickMedianKey

void Chunk::pickMedianKey(BSONObj& medianKey) const {
    // Ask the mongod holding this chunk to figure out the split points.
    ScopedDbConnection conn(_getShardConnectionString());
    BSONObj result;
    BSONObjBuilder cmd;
    cmd.append("splitVector", _manager->getns());
    cmd.append("keyPattern", _manager->getShardKeyPattern().toBSON());
    cmd.append("min", getMin());
    cmd.append("max", getMax());
    cmd.appendBool("force", true);
    BSONObj cmdObj = cmd.obj();

    if (!conn->runCommand("admin", cmdObj, result)) {
        conn.done();
        ostringstream os;
        os << "splitVector command (median key) failed: " << result;
        uassert(13503, os.str(), 0);
    }

    BSONObjIterator it(result.getObjectField("splitKeys"));
    if (it.more()) {
        medianKey = it.next().Obj().getOwned();
    }

    conn.done();
}
开发者ID:alabid,项目名称:mongo,代码行数:26,代码来源:chunk.cpp

示例14: ensureIndex

    void Helpers::ensureIndex(const char *ns, BSONObj keyPattern, bool unique, const char *name) {
        NamespaceDetails *d = nsdetails(ns);
        if( d == 0 )
            return;

        {
            NamespaceDetails::IndexIterator i = d->ii();
            while( i.more() ) {
                if( i.next().keyPattern().woCompare(keyPattern) == 0 )
                    return;
            }
        }

        if( d->nIndexes >= NamespaceDetails::NIndexesMax ) {
            problem() << "Helper::ensureIndex fails, MaxIndexes exceeded " << ns << '\n';
            return;
        }

        string system_indexes = cc().database()->name + ".system.indexes";

        BSONObjBuilder b;
        b.append("name", name);
        b.append("ns", ns);
        b.append("key", keyPattern);
        b.appendBool("unique", unique);
        BSONObj o = b.done();

        theDataFileMgr.insert(system_indexes.c_str(), o.objdata(), o.objsize());
    }
开发者ID:abhishekkumar1989,项目名称:mongo,代码行数:29,代码来源:dbhelpers.cpp

示例15: handlePossibleShardedMessage

    bool handlePossibleShardedMessage( Message &m, DbResponse &dbresponse ){

        if ( shardConfigServer.empty() ){
            return false;
        }

        int op = m.data->operation();
        if ( op < 2000 || op >= 3000 )
            return false;

        
        const char *ns = m.data->_data + 4;
        string errmsg;
        if ( shardVersionOk( ns , errmsg ) ){
            return false;
        }

        log() << "shardVersionOk failed  ns:" << ns << " " << errmsg << endl;
        
        if ( doesOpGetAResponse( op ) ){
            BufBuilder b( 32768 );
            b.skip( sizeof( QueryResult ) );
            {
                BSONObj obj = BSON( "$err" << errmsg );
                b.append( obj.objdata() , obj.objsize() );
            }
            
            QueryResult *qr = (QueryResult*)b.buf();
            qr->_resultFlags() = QueryResult::ResultFlag_ErrSet | QueryResult::ResultFlag_ShardConfigStale;
            qr->len = b.len();
            qr->setOperation( opReply );
            qr->cursorId = 0;
            qr->startingFrom = 0;
            qr->nReturned = 1;
            b.decouple();

            Message * resp = new Message();
            resp->setData( qr , true );
            
            dbresponse.response = resp;
            dbresponse.responseTo = m.data->id;
            return true;
        }
        
        OID * clientID = clientServerIds.get();
        massert( 10422 ,  "write with bad shard config and no server id!" , clientID );
        
        log() << "got write with an old config - writing back" << endl;

        BSONObjBuilder b;
        b.appendBool( "writeBack" , true );
        b.append( "ns" , ns );
        b.appendBinData( "msg" , m.data->len , bdtCustom , (char*)(m.data) );
        log() << "writing back msg with len: " << m.data->len << " op: " << m.data->_operation << endl;
        clientQueues[clientID->str()]->push( b.obj() );

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


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