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


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

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


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

示例1: run

 virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     if( cmdObj.hasElement("expireOplogDays") || cmdObj.hasElement("expireOplogHours") ) {
         uint32_t expireOplogDays = cmdLine.expireOplogDays;
         uint32_t expireOplogHours = cmdLine.expireOplogHours;
         if (cmdObj.hasElement("expireOplogHours")) {
             BSONElement e = cmdObj["expireOplogHours"];
             if (!e.isNumber()) {
                 errmsg = "bad expireOplogHours";
                 return false;
             }
             expireOplogHours = e.numberLong();
         }
         if (cmdObj.hasElement("expireOplogDays")) {
             BSONElement e = cmdObj["expireOplogDays"];
             if (!e.isNumber()) {
                 errmsg = "bad expireOplogDays";
                 return false;
             }
             expireOplogDays = e.numberLong();
         }
         theReplSet->changeExpireOplog(expireOplogDays, expireOplogHours);
     }
     return true;
 }
开发者ID:calexandre,项目名称:mongo,代码行数:24,代码来源:replset_commands.cpp

示例2: isLegacyCenterSphere

 bool GeoParser::isLegacyCenterSphere(const BSONObj &obj) {
     BSONObjIterator typeIt(obj);
     BSONElement type = typeIt.next();
     if (!type.isABSONObj()) { return false; }
     bool isCenterSphere = mongoutils::str::equals(type.fieldName(), "$centerSphere");
     if (!isCenterSphere) { return false; }
     BSONObjIterator objIt(type.embeddedObject());
     BSONElement center = objIt.next();
     if (!center.isABSONObj()) { return false; }
     if (!isLegacyPoint(center.Obj())) { return false; }
     if (!objIt.more()) { return false; }
     BSONElement radius = objIt.next();
     if (!radius.isNumber()) { return false; }
     return true;
 }
开发者ID:4commerce-technologies-AG,项目名称:mongo,代码行数:15,代码来源:geoparser.cpp

示例3: woCompare

 /* wo = "well ordered" */
 int BSONElement::woCompare( const BSONElement &e,
                             bool considerFieldName ) const {
     int lt = (int) canonicalType();
     int rt = (int) e.canonicalType();
     int x = lt - rt;
     if( x != 0 && (!isNumber() || !e.isNumber()) )
         return x;
     if ( considerFieldName ) {
         x = strcmp(fieldName(), e.fieldName());
         if ( x != 0 )
             return x;
     }
     x = compareElementValues(*this, e);
     return x;
 }
开发者ID:erickt,项目名称:mongo,代码行数:16,代码来源:jsobj.cpp

示例4: parsePointWithMaxDistance

bool GeoParser::parsePointWithMaxDistance(const BSONObj& obj, PointWithCRS* out, double* maxOut) {
    BSONObjIterator it(obj);
    if (!it.more()) {
        return false;
    }

    BSONElement lng = it.next();
    if (!lng.isNumber()) {
        return false;
    }
    if (!it.more()) {
        return false;
    }

    BSONElement lat = it.next();
    if (!lat.isNumber()) {
        return false;
    }
    if (!it.more()) {
        return false;
    }

    BSONElement dist = it.next();
    if (!dist.isNumber()) {
        return false;
    }
    if (it.more()) {
        return false;
    }

    out->oldPoint.x = lng.number();
    out->oldPoint.y = lat.number();
    out->crs = FLAT;
    *maxOut = dist.number();
    return true;
}
开发者ID:Andiry,项目名称:mongo,代码行数:36,代码来源:geoparser.cpp

示例5: program

 MongoProgramRunner( const BSONObj &args ) {
     assert( args.nFields() > 0 );
     string program( args.firstElement().valuestrsafe() );
     
     assert( !program.empty() );
     boost::filesystem::path programPath = ( boost::filesystem::path( argv0 ) ).branch_path() / program;
     massert( "couldn't find " + programPath.native_file_string(), boost::filesystem::exists( programPath ) );
     
     port_ = -1;
     argv_ = new char *[ args.nFields() + 1 ];
     {
         string s = programPath.native_file_string();
         if ( s == program )
             s = "./" + s;
         argv_[ 0 ] = copyString( s.c_str() );
     }
     
     BSONObjIterator j( args );
     j.next();
     for( int i = 1; i < args.nFields(); ++i ) {
         BSONElement e = j.next();
         string str;
         if ( e.isNumber() ) {
             stringstream ss;
             ss << e.number();
             str = ss.str();
         } else {
             assert( e.type() == mongo::String );
             str = e.valuestr();
         }
         char *s = copyString( str.c_str() );
         if ( string( "--port" ) == s )
             port_ = -2;
         else if ( port_ == -2 )
             port_ = strtol( s, 0, 10 );
         argv_[ i ] = s;
     }
     argv_[ args.nFields() ] = 0;
     
     if ( program != "mongod" && program != "mongos" && program != "mongobridge" )
         port_ = 0;
     else
         assert( port_ > 0 );
     if ( port_ > 0 && dbs.count( port_ ) != 0 ){
         cerr << "count for port: " << port_ << " is not 0 is: " << dbs.count( port_ ) << endl;
         assert( dbs.count( port_ ) == 0 );        
     }
 }
开发者ID:alanw,项目名称:mongo,代码行数:48,代码来源:utils.cpp

示例6: DBException

    auto_ptr<DBClientCursor> DBClientReplicaSet::checkSlaveQueryResult( auto_ptr<DBClientCursor> result ){
        BSONObj error;
        bool isError = result->peekError( &error );
        if( ! isError ) return result;

        // We only check for "not master or secondary" errors here

        // If the error code here ever changes, we need to change this code also
        BSONElement code = error["code"];
        if( code.isNumber() && code.Int() == 13436 /* not master or secondary */ ){
            isntSecondary();
            throw DBException( str::stream() << "slave " << _slaveHost.toString() << " is no longer secondary", 14812 );
        }

        return result;
    }
开发者ID:cangove,项目名称:mongo,代码行数:16,代码来源:dbclient_rs.cpp

示例7: extractVersion

    unsigned long long extractVersion( BSONElement e , string& errmsg ) {
        if ( e.eoo() ) {
            errmsg = "no version";
            return 0;
        }

        if ( e.isNumber() )
            return (unsigned long long)e.number();

        if ( e.type() == Date || e.type() == Timestamp )
            return e._numberLong();


        errmsg = "version is not a numeric type";
        return 0;
    }
开发者ID:Kenterfie,项目名称:mongo,代码行数:16,代码来源:d_state.cpp

示例8: run

        bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int,
                 string& errmsg, BSONObjBuilder& result, bool fromRepl) {
            const string ns = dbname + "." + cmdObj.firstElement().valuestr();
            Client::ReadContext ctx(ns);

            Database* db = ctx.ctx().db();
            if ( !db ) {
                errmsg = "can't find ns";
                return false;
            }

            Collection* collection = db->getCollection( ns );
            if ( !collection ) {
                errmsg = "can't find ns";
                return false;
            }

            vector<IndexDescriptor*> idxs;
            collection->getIndexCatalog()->findIndexByType(IndexNames::GEO_HAYSTACK, idxs);
            if (idxs.size() == 0) {
                errmsg = "no geoSearch index";
                return false;
            }
            if (idxs.size() > 1) {
                errmsg = "more than 1 geosearch index";
                return false;
            }

            BSONElement nearElt = cmdObj["near"];
            BSONElement maxDistance = cmdObj["maxDistance"];
            BSONElement search = cmdObj["search"];

            uassert(13318, "near needs to be an array", nearElt.isABSONObj());
            uassert(13319, "maxDistance needs a number", maxDistance.isNumber());
            uassert(13320, "search needs to be an object", search.type() == Object);

            unsigned limit = 50;
            if (cmdObj["limit"].isNumber())
                limit = static_cast<unsigned>(cmdObj["limit"].numberInt());

            IndexDescriptor* desc = idxs[0];
            HaystackAccessMethod* ham =
                static_cast<HaystackAccessMethod*>( collection->getIndexCatalog()->getIndex(desc) );
            ham->searchCommand(collection, nearElt.Obj(), maxDistance.numberDouble(), search.Obj(),
                               &result, limit);
            return 1;
        }
开发者ID:Albert-B-P,项目名称:mongo,代码行数:47,代码来源:haystack.cpp

示例9: init

    Status ModifierInc::init(const BSONElement& modExpr, const Options& opts,
                             bool* positional) {

        //
        // field name analysis
        //

        // Perform standard field name and updateable checks.
        _fieldRef.parse(modExpr.fieldName());
        Status status = fieldchecker::isUpdatable(_fieldRef);
        if (! status.isOK()) {
            return status;
        }

        // If a $-positional operator was used, get the index in which it occurred
        // and ensure only one occurrence.
        size_t foundCount;
        bool foundDollar = fieldchecker::isPositional(_fieldRef, &_posDollar, &foundCount);

        if (positional)
            *positional = foundDollar;

        if (foundDollar && foundCount > 1) {
            return Status(ErrorCodes::BadValue,
                          str::stream() << "Too many positional (i.e. '$') elements found in path '"
                                        << _fieldRef.dottedField() << "'");
        }

        //
        // value analysis
        //

        if (!modExpr.isNumber()) {
            // TODO: Context for mod error messages would be helpful
            // include mod code, etc.
            return Status(ErrorCodes::TypeMismatch,
                          str::stream() << "Cannot "
                                        << (_mode == MODE_INC ? "increment" : "multiply")
                                        << " with non-numeric argument: {"
                                        << modExpr << "}");
        }

        _val = modExpr;
        dassert(_val.isValid());

        return Status::OK();
    }
开发者ID:7segments,项目名称:mongo-1,代码行数:47,代码来源:modifier_inc.cpp

示例10: uassert

    intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson(
            BSONElement elem,
            const intrusive_ptr<ExpressionContext> &pExpCtx) {
        uassert(15972, str::stream() << DocumentSourceSkip::skipName <<
                ":  the value to skip must be a number",
                elem.isNumber());

        intrusive_ptr<DocumentSourceSkip> pSkip(
            DocumentSourceSkip::create(pExpCtx));

        pSkip->_skip = elem.numberLong();
        uassert(15956, str::stream() << DocumentSourceSkip::skipName <<
                ":  the number to skip cannot be negative",
                pSkip->_skip >= 0);

        return pSkip;
    }
开发者ID:3rf,项目名称:mongo,代码行数:17,代码来源:document_source_skip.cpp

示例11: genIndexName

    string DBClientWithCommands::genIndexName( const BSONObj& keys ) {
        stringstream ss;

        bool first = 1;
        for ( BSONObjIterator i(keys); i.more(); ) {
            BSONElement f = i.next();

            if ( first )
                first = 0;
            else
                ss << "_";

            ss << f.fieldName() << "_";
            if( f.isNumber() )
                ss << f.numberInt();
        }
        return ss.str();
    }
开发者ID:RyokoAkizuki,项目名称:freshcity,代码行数:18,代码来源:dbclient.cpp

示例12: twoDSphereBoundsIncrement

    static double twoDSphereBoundsIncrement(const IndexDescriptor* s2Index) {

        // The user can override this so we honor it.  We could ignore it though -- it's just used
        // to set _radiusIncrement, not to do any covering.
        // TODO: Make this parsed somewhere else
        int finestIndexedLevel;
        BSONElement finestLevelEl = s2Index->infoObj()["finestIndexedLevel"];
        if (finestLevelEl.isNumber()) {
            finestIndexedLevel = finestLevelEl.numberInt();
        }
        else {
            finestIndexedLevel = S2::kAvgEdge.GetClosestLevel(500.0 / kRadiusOfEarthInMeters);
        }

        // Start with a conservative bounds increment.  When we're done searching a shell we
        // increment the two radii by this.
        return 5 * S2::kAvgEdge.GetValue(finestIndexedLevel) * kRadiusOfEarthInMeters;
    }
开发者ID:Mickael-van-der-Beek,项目名称:mongo,代码行数:18,代码来源:geo_near.cpp

示例13: run

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

            string ns = dbname + "." + cmdObj.firstElement().valuestr();

            NamespaceDetails * d = nsdetails( ns.c_str() );
            if ( ! d ) {
                errmsg = "can't find ns";
                return false;
            }

            vector<int> idxs;
            d->findIndexByType( GEOSEARCHNAME , idxs );
            if ( idxs.size() == 0 ) {
                errmsg = "no geoSearch index";
                return false;
            }
            if ( idxs.size() > 1 ) {
                errmsg = "more than 1 geosearch index";
                return false;
            }

            int idxNum = idxs[0];

            IndexDetails& id = d->idx( idxNum );
            GeoHaystackSearchIndex * si = (GeoHaystackSearchIndex*)id.getSpec().getType();
            verify( &id == si->getDetails() );

            BSONElement n = cmdObj["near"];
            BSONElement maxDistance = cmdObj["maxDistance"];
            BSONElement search = cmdObj["search"];

            uassert( 13318 , "near needs to be an array" , n.isABSONObj() );
            uassert( 13319 , "maxDistance needs a number" , maxDistance.isNumber() );
            uassert( 13320 , "search needs to be an object" , search.type() == Object );

            unsigned limit = 50;
            if ( cmdObj["limit"].isNumber() )
                limit = (unsigned)cmdObj["limit"].numberInt();

            si->searchCommand( d , idxNum , n.Obj() , maxDistance.numberDouble() , search.Obj() , result , limit );

            return 1;
        }
开发者ID:89snake89,项目名称:mongo,代码行数:43,代码来源:haystack.cpp

示例14: it

    // static
    void QueryPlannerIXSelect::stripInvalidAssignmentsTo2dsphereIndices(
        MatchExpression* node,
        const vector<IndexEntry>& indices) {

        for (size_t i = 0; i < indices.size(); ++i) {
            const IndexEntry& index = indices[i];

            // We only worry about 2dsphere indices.
            if (INDEX_2DSPHERE != index.type) {
                continue;
            }

            // They also have to be V2.  Both ignore the sparse flag but V1 is
            // never-sparse, V2 geo-sparse.
            BSONElement elt = index.infoObj["2dsphereIndexVersion"];
            if (elt.eoo()) {
                continue;
            }
            if (!elt.isNumber()) {
                continue;
            }
            if (2 != elt.numberInt()) {
                continue;
            }

            // If every field is geo don't bother doing anything.
            bool allFieldsGeo = true;
            BSONObjIterator it(index.keyPattern);
            while (it.more()) {
                BSONElement elt = it.next();
                if (String != elt.type()) {
                    allFieldsGeo = false;
                    break;
                }
            }
            if (allFieldsGeo) {
                continue;
            }

            // Remove bad assignments from this index.
            stripInvalidAssignmentsTo2dsphereIndex(node, i);
        }
    }
开发者ID:Benguang,项目名称:mongo,代码行数:44,代码来源:planner_ixselect.cpp

示例15: transformOrderFromArrayFormat

 /* This is for languages whose "objects" are not well ordered (JSON is well ordered).
  [ { a : ... } , { b : ... } ] -> { a : ..., b : ... }
  */
 static BSONObj transformOrderFromArrayFormat(BSONObj order) {
     /* note: this is slow, but that is ok as order will have very few pieces */
     BSONObjBuilder b;
     char p[2] = "0";
     
     while ( 1 ) {
         BSONObj j = order.getObjectField(p);
         if ( j.isEmpty() )
             break;
         BSONElement e = j.firstElement();
         uassert( 10102 , "bad order array", !e.eoo());
         uassert( 10103 , "bad order array [2]", e.isNumber());
         b.append(e);
         (*p)++;
         uassert( 10104 , "too many ordering elements", *p <= '9');
     }
     
     return b.obj();
 }
开发者ID:bob0wang,项目名称:mongo,代码行数:22,代码来源:parsed_query.cpp


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