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


C++ BSONElement::valuestr方法代码示例

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


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

示例1: killMatchingIndexBuilds

        virtual std::vector<BSONObj> stopIndexBuilds(Database* db, 
                                                     const BSONObj& cmdObj) {
            std::string toDeleteNs = db->name() + "." + cmdObj.firstElement().valuestr();
            Collection* collection = db->getCollection(toDeleteNs);
            IndexCatalog::IndexKillCriteria criteria;

            // Get index name to drop
            BSONElement toDrop = cmdObj.getField("index");

            if (toDrop.type() == String) {
                // Kill all in-progress indexes
                if (strcmp("*", toDrop.valuestr()) == 0) {
                    criteria.ns = toDeleteNs;
                    return IndexBuilder::killMatchingIndexBuilds(collection, criteria);
                }
                // Kill an in-progress index by name
                else {
                    criteria.name = toDrop.valuestr();
                    return IndexBuilder::killMatchingIndexBuilds(collection, criteria);
                }
            }
            // Kill an in-progress index build by index key
            else if (toDrop.type() == Object) {
                criteria.key = toDrop.Obj();
                return IndexBuilder::killMatchingIndexBuilds(collection, criteria);
            }

            return std::vector<BSONObj>();
        }
开发者ID:LearyLX,项目名称:mongo,代码行数:29,代码来源:drop_indexes.cpp

示例2: getFieldName

    bool getFieldName(OperationContext* txn,
                      Collection* collection,
                      IndexCatalog* indexCatalog,
                      string* fieldOut,
                      string* errOut,
                      bool* isFrom2D) {
        vector<IndexDescriptor*> idxs;

        // First, try 2d.
        collection->getIndexCatalog()->findIndexByType(txn, IndexNames::GEO_2D, idxs);
        if (idxs.size() > 1) {
            *errOut = "more than one 2d index, not sure which to run geoNear on";
            return false;
        }

        if (1 == idxs.size()) {
            BSONObj indexKp = idxs[0]->keyPattern();
            BSONObjIterator kpIt(indexKp);
            while (kpIt.more()) {
                BSONElement elt = kpIt.next();
                if (String == elt.type() && IndexNames::GEO_2D == elt.valuestr()) {
                    *fieldOut = elt.fieldName();
                    *isFrom2D = true;
                    return true;
                }
            }
        }

        // Next, 2dsphere.
        idxs.clear();
        collection->getIndexCatalog()->findIndexByType(txn, IndexNames::GEO_2DSPHERE, idxs);
        if (0 == idxs.size()) {
            *errOut = "no geo indices for geoNear";
            return false;
        }

        if (idxs.size() > 1) {
            *errOut = "more than one 2dsphere index, not sure which to run geoNear on";
            return false;
        }

        // 1 == idx.size()
        BSONObj indexKp = idxs[0]->keyPattern();
        BSONObjIterator kpIt(indexKp);
        while (kpIt.more()) {
            BSONElement elt = kpIt.next();
            if (String == elt.type() && IndexNames::GEO_2DSPHERE == elt.valuestr()) {
                *fieldOut = elt.fieldName();
                *isFrom2D = false;
                return true;
            }
        }

        return false;
    }
开发者ID:wenhailong,项目名称:mongo,代码行数:55,代码来源:geo_near_cmd.cpp

示例3: loadStored

    void Scope::loadStored( bool ignoreNotConnected ){
        if ( _localDBName.size() == 0 ){
            if ( ignoreNotConnected )
                return;
            uassert( 10208 ,  "need to have locallyConnected already" , _localDBName.size() );
        }
        if ( _loadedVersion == _lastVersion )
            return;
        
        _loadedVersion = _lastVersion;

        string coll = _localDBName + ".system.js";
        
        static DBClientBase * db = createDirectClient();
        auto_ptr<DBClientCursor> c = db->query( coll , Query() );
        assert( c.get() );
        
        set<string> thisTime;
        
        while ( c->more() ){
            BSONObj o = c->next();

            BSONElement n = o["_id"];
            BSONElement v = o["value"];
            
            uassert( 10209 ,  "name has to be a string" , n.type() == String );
            uassert( 10210 ,  "value has to be set" , v.type() != EOO );
            
            setElement( n.valuestr() , v );

            thisTime.insert( n.valuestr() );
            _storedNames.insert( n.valuestr() );
            
        }

        // --- remove things from scope that were removed

        list<string> toremove;

        for ( set<string>::iterator i=_storedNames.begin(); i!=_storedNames.end(); i++ ){
            string n = *i;
            if ( thisTime.count( n ) == 0 )
                toremove.push_back( n );
        }
        
        for ( list<string>::iterator i=toremove.begin(); i!=toremove.end(); i++ ){
            string n = *i;
            _storedNames.erase( n );
            execSetup( (string)"delete " + n , "clean up scope" );
        }

    }
开发者ID:meganyao,项目名称:mongo,代码行数:52,代码来源:engine.cpp

示例4: loadStored

    void Scope::loadStored(bool ignoreNotConnected) {
        if (_localDBName.size() == 0) {
            if (ignoreNotConnected)
                return;
            uassert(10208,  "need to have locallyConnected already", _localDBName.size());
        }

        if (_loadedVersion == _lastVersion)
            return;

        _loadedVersion = _lastVersion;
        string coll = _localDBName + ".system.js";

        DBClientBase* directDBClient = createDirectClient();
        auto_ptr<DBClientCursor> c = directDBClient->query(coll, Query(), 0, 0, NULL,
            QueryOption_SlaveOk, 0);
        massert(16669, "unable to get db client cursor from query", c.get());

        set<string> thisTime;
        while (c->more()) {
            BSONObj o = c->nextSafe();
            BSONElement n = o["_id"];
            BSONElement v = o["value"];

            uassert(10209, str::stream() << "name has to be a string: " << n, n.type() == String);
            uassert(10210, "value has to be set", v.type() != EOO);

            try {
                setElement(n.valuestr(), v);
                thisTime.insert(n.valuestr());
                _storedNames.insert(n.valuestr());
            }
            catch (const DBException& setElemEx) {
                log() << "unable to load stored JavaScript function " << n.valuestr()
                      << "(): " << setElemEx.what() << endl;
            }
        }

        // remove things from scope that were removed from the system.js collection
        for (set<string>::iterator i = _storedNames.begin(); i != _storedNames.end(); ) {
            if (thisTime.count(*i) == 0) {
                string toDelete = str::stream() << "delete " << *i;
                _storedNames.erase(i++);
                execSetup(toDelete, "clean up scope");
            }
            else {
                ++i;
            }
        }
    }
开发者ID:MohdVara,项目名称:mongo,代码行数:50,代码来源:engine.cpp

示例5: loadStored

    void Scope::loadStored( bool ignoreNotConnected ){
        if ( _localDBName.size() == 0 ){
            if ( ignoreNotConnected )
                return;
            uassert( "need to have locallyConnected already" , _localDBName.size() );
        }
        if ( _loadedVersion == _lastVersion )
            return;
        
        _loadedVersion = _lastVersion;

        static DBClientBase * db = createDirectClient();
        
        auto_ptr<DBClientCursor> c = db->query( _localDBName + ".system.js" , Query() );
        while ( c->more() ){
            BSONObj o = c->next();

            BSONElement n = o["_id"];
            BSONElement v = o["value"];
            
            uassert( "name has to be a string" , n.type() == String );
            uassert( "value has to be set" , v.type() != EOO );
            
            setElement( n.valuestr() , v );
        }
    }
开发者ID:petewarden,项目名称:mongo,代码行数:26,代码来源:engine.cpp

示例6: expressionParserWhereCallbackReal

    StatusWithMatchExpression expressionParserWhereCallbackReal(const BSONElement& where) {
        if ( !haveClient() )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no current client needed for $where" );

        Client::Context* context = cc().getContext();
        if ( !context )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no context in $where parsing" );

        const char* ns = context->ns();
        if ( !ns )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no ns in $where parsing" );

        if ( !globalScriptEngine )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no globalScriptEngine in $where parsing" );

        auto_ptr<WhereMatchExpression> exp( new WhereMatchExpression() );
        if ( where.type() == String || where.type() == Code ) {
            Status s = exp->init( ns, where.valuestr(), BSONObj() );
            if ( !s.isOK() )
                return StatusWithMatchExpression( s );
            return StatusWithMatchExpression( exp.release() );
        }

        if ( where.type() == CodeWScope ) {
            Status s = exp->init( ns,
                                  where.codeWScopeCode(),
                                  BSONObj( where.codeWScopeScopeDataUnsafe() ) );
            if ( !s.isOK() )
                return StatusWithMatchExpression( s );
            return StatusWithMatchExpression( exp.release() );
        }

        return StatusWithMatchExpression( ErrorCodes::BadValue, "$where got bad type" );
    }
开发者ID:ChowZenki,项目名称:mongo,代码行数:34,代码来源:expression_where.cpp

示例7: i

    S2AccessMethod::S2AccessMethod(IndexDescriptor *descriptor)
        : BtreeBasedAccessMethod(descriptor) {

        // Set up basic params.
        _params.maxKeysPerInsert = 200;
        // This is advisory.
        _params.maxCellsInCovering = 50;
        // Near distances are specified in meters...sometimes.
        _params.radius = S2IndexingParams::kRadiusOfEarthInMeters;
        // These are not advisory.
        _params.finestIndexedLevel = configValueWithDefault(descriptor, "finestIndexedLevel",
            S2::kAvgEdge.GetClosestLevel(500.0 / _params.radius));
        _params.coarsestIndexedLevel = configValueWithDefault(descriptor, "coarsestIndexedLevel",
            S2::kAvgEdge.GetClosestLevel(100 * 1000.0 / _params.radius));
        uassert(16747, "coarsestIndexedLevel must be >= 0", _params.coarsestIndexedLevel >= 0);
        uassert(16748, "finestIndexedLevel must be <= 30", _params.finestIndexedLevel <= 30);
        uassert(16749, "finestIndexedLevel must be >= coarsestIndexedLevel",
                _params.finestIndexedLevel >= _params.coarsestIndexedLevel);

        int geoFields = 0;
        // Categorize the fields we're indexing and make sure we have a geo field.
        BSONObjIterator i(descriptor->keyPattern());
        while (i.more()) {
            BSONElement e = i.next();
            if (e.type() == String && S2IndexingParams::SPHERE_2D_NAME == e.valuestr()) {
                ++geoFields;
            }
        }
        uassert(16750, "Expect at least one geo field, spec=" + descriptor->keyPattern().toString(),
                geoFields >= 1);
    }
开发者ID:10genReviews,项目名称:mongo,代码行数:31,代码来源:s2_access_method.cpp

示例8: fixindex

    /* for index info object:
         { "name" : "name_1" , "ns" : "foo.index3" , "key" :  { "name" : 1.0 } }
       we need to fix up the value in the "ns" parameter so that the name prefix is correct on a
       copy to a new name.
    */
    static BSONObj fixindex(BSONObj o, const string &dbname) {
        BSONObjBuilder b;
        BSONObjIterator i(o);
        while ( i.moreWithEOO() ) {
            BSONElement e = i.next();
            if ( e.eoo() )
                break;

            // for now, skip the "v" field so that v:0 indexes will be upgraded to v:1
            if ( string("v") == e.fieldName() ) {
                continue;
            }

            if ( string("ns") == e.fieldName() ) {
                uassert( 
                    10024 , 
                    "bad ns field for index during dbcopy", 
                    e.type() == String
                    );
                const char *p = strchr(e.valuestr(), '.');
                uassert( 10025 , "bad ns field for index during dbcopy [2]", p);
                string newname = dbname + p;
                b.append("ns", newname);
            }
            else
                b.append(e);
        }
        BSONObj res= b.obj();
        return res;
    }
开发者ID:lucciano,项目名称:mongo-1,代码行数:35,代码来源:cloner.cpp

示例9: i

        GeoHaystackSearchIndex(const IndexPlugin* plugin, const IndexSpec* spec)
            : IndexType(plugin, spec) {

            BSONElement e = spec->info["bucketSize"];
            uassert(13321, "need bucketSize", e.isNumber());
            _bucketSize = e.numberDouble();
            uassert(16455, "bucketSize cannot be zero", _bucketSize != 0.0);

            // Example:
            // db.foo.ensureIndex({ pos : "geoHaystack", type : 1 }, { bucketSize : 1 })
            BSONObjIterator i(spec->keyPattern);
            while (i.more()) {
                BSONElement e = i.next();
                if (e.type() == String && GEOSEARCHNAME == e.valuestr()) {
                    uassert(13314, "can't have more than one geo field", _geoField.size() == 0);
                    uassert(13315, "the geo field has to be first in index",
                            _otherFields.size() == 0);
                    _geoField = e.fieldName();
                } else {
                    // TODO(hk): Do we want to do any checking on e.type and e.valuestr?
                    uassert(13326, "geoSearch can only have 1 non-geo field for now",
                            _otherFields.size() == 0);
                    _otherFields.push_back(e.fieldName());
                }
            }

            uassert(13316, "no geo field specified", _geoField.size());
            // XXX: Fix documentation that says the other field is optional; code says it's mandatory.
            uassert(13317, "no non-geo fields specified", _otherFields.size());
        }
开发者ID:Hasib100,项目名称:mongo,代码行数:30,代码来源:haystack.cpp

示例10: i

        GeoHaystackSearchIndex( const IndexPlugin* plugin , const IndexSpec* spec )
            : IndexType( plugin , spec ) {

            BSONElement e = spec->info["bucketSize"];
            uassert( 13321 , "need bucketSize" , e.isNumber() );
            _bucketSize = e.numberDouble();

            BSONObjBuilder orderBuilder;

            BSONObjIterator i( spec->keyPattern );
            while ( i.more() ) {
                BSONElement e = i.next();
                if ( e.type() == String && GEOSEARCHNAME == e.valuestr() ) {
                    uassert( 13314 , "can't have 2 geo fields" , _geo.size() == 0 );
                    uassert( 13315 , "2d has to be first in index" , _other.size() == 0 );
                    _geo = e.fieldName();
                }
                else {
                    _other.push_back( e.fieldName() );
                }
                orderBuilder.append( "" , 1 );
            }

            uassert( 13316 , "no geo field specified" , _geo.size() );
            uassert( 13317 , "no other fields specified" , _other.size() );
            uassert( 13326 , "quadrant search can only have 1 other field for now" , _other.size() == 1 );
            _order = orderBuilder.obj();
        }
开发者ID:89snake89,项目名称:mongo,代码行数:28,代码来源:haystack.cpp

示例11: isDiskLocMeta

 // static
 bool LiteParsedQuery::isDiskLocMeta(BSONElement elt) {
     // elt must be foo: {$meta: "diskloc"}
     if (mongo::Object != elt.type()) {
         return false;
     }
     BSONObj metaObj = elt.Obj();
     BSONObjIterator metaIt(metaObj);
     // must have exactly 1 element
     if (!metaIt.more()) {
         return false;
     }
     BSONElement metaElt = metaIt.next();
     if (!mongoutils::str::equals("$meta", metaElt.fieldName())) {
         return false;
     }
     if (mongo::String != metaElt.type()) {
         return false;
     }
     if (LiteParsedQuery::metaDiskLoc != metaElt.valuestr()) {
         return false;
     }
     // must have exactly 1 element
     if (metaIt.more()) {
         return false;
     }
     return true;
 }
开发者ID:AshishThakur,项目名称:mongo,代码行数:28,代码来源:lite_parsed_query.cpp

示例12: init

   INT32 _clsAlterDC::init( INT32 flags, INT64 numToSkip,
                            INT64 numToReturn, const CHAR *pMatcherBuff,
                            const CHAR *pSelectBuff,
                            const CHAR *pOrderByBuff,
                            const CHAR *pHintBuff )
   {
      INT32 rc = SDB_OK ;

      try
      {
         BSONObj query( pMatcherBuff ) ;
         BSONElement eleAction = query.getField( FIELD_NAME_ACTION ) ;
         if ( String != eleAction.type() )
         {
            PD_LOG( PDERROR, "The field[%s] is not valid in command[%s]'s "
                    "param[%s]", FIELD_NAME_ACTION, NAME_ALTER_DC,
                    query.toString().c_str() ) ;
            rc = SDB_INVALIDARG ;
            goto error ;
         }
         _pAction = eleAction.valuestr() ;
      }
      catch( std::exception &e )
      {
         PD_LOG( PDERROR, "Parse params occur exception: %s", e.what() ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
开发者ID:Andrew8305,项目名称:SequoiaDB,代码行数:34,代码来源:clsCommand.cpp

示例13: _getOption

 int _getOption( BSONElement e , int def ) {
     if ( e.isNumber() )
         return e.numberInt();
     if ( e.type() == String )
         return atoi( e.valuestr() );
     return def;
 }
开发者ID:DeathBorn,项目名称:mongo,代码行数:7,代码来源:restapi.cpp

示例14: parseTwoDParams

void ExpressionParams::parseTwoDParams(const BSONObj& infoObj, TwoDIndexingParams* out) {
    BSONObjIterator i(infoObj.getObjectField("key"));

    while (i.more()) {
        BSONElement e = i.next();
        if (e.type() == String && IndexNames::GEO_2D == e.valuestr()) {
            uassert(16800, "can't have 2 geo fields", out->geo.size() == 0);
            uassert(16801, "2d has to be first in index", out->other.size() == 0);
            out->geo = e.fieldName();
        } else {
            int order = 1;
            if (e.isNumber()) {
                order = static_cast<int>(e.Number());
            }
            out->other.push_back(std::make_pair(e.fieldName(), order));
        }
    }

    uassert(16802, "no geo field specified", out->geo.size());

    GeoHashConverter::Parameters hashParams;
    Status paramStatus = GeoHashConverter::parseParameters(infoObj, &hashParams);
    uassertStatusOK(paramStatus);

    out->geoHashConverter.reset(new GeoHashConverter(hashParams));
}
开发者ID:kangic,项目名称:mongo,代码行数:26,代码来源:expression_params.cpp

示例15: fillWriterVectors

void fillWriterVectors(const std::deque<BSONObj>& ops,
                       std::vector<std::vector<BSONObj>>* writerVectors) {
    for (std::deque<BSONObj>::const_iterator it = ops.begin(); it != ops.end(); ++it) {
        const BSONElement e = it->getField("ns");
        verify(e.type() == String);
        const char* ns = e.valuestr();
        int len = e.valuestrsize();
        uint32_t hash = 0;
        MurmurHash3_x86_32(ns, len, 0, &hash);

        const char* opType = it->getField("op").valuestrsafe();

        if (getGlobalServiceContext()->getGlobalStorageEngine()->supportsDocLocking() &&
            isCrudOpType(opType)) {
            BSONElement id;
            switch (opType[0]) {
                case 'u':
                    id = it->getField("o2").Obj()["_id"];
                    break;
                case 'd':
                case 'i':
                    id = it->getField("o").Obj()["_id"];
                    break;
            }

            const size_t idHash = BSONElement::Hasher()(id);
            MurmurHash3_x86_32(&idHash, sizeof(idHash), hash, &hash);
        }

        (*writerVectors)[hash % writerVectors->size()].push_back(*it);
    }
}
开发者ID:Jonekee,项目名称:mongo,代码行数:32,代码来源:sync_tail.cpp


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