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


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

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


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

示例1: set

 virtual Status set(const BSONElement& newValueElement) {
     long long newValue;
     if (!newValueElement.isNumber()) {
         StringBuilder sb;
         sb << "Expected number type for journalCommitInterval via setParameter command: "
            << newValueElement;
         return Status(ErrorCodes::BadValue, sb.str());
     }
     if (newValueElement.type() == NumberDouble &&
             (newValueElement.numberDouble() - newValueElement.numberLong()) > 0) {
         StringBuilder sb;
         sb << "journalCommitInterval must be a whole number: "
            << newValueElement;
         return Status(ErrorCodes::BadValue, sb.str());
     }
     newValue = newValueElement.numberLong();
     if (newValue <= 1 || newValue >= 500) {
         StringBuilder sb;
         sb << "journalCommitInterval must be between 1 and 500, but attempted to set to: "
            << newValue;
         return Status(ErrorCodes::BadValue, sb.str());
     }
     storageGlobalParams.journalCommitInterval = static_cast<unsigned>(newValue);
     return Status::OK();
 }
开发者ID:JavaInCloud,项目名称:mongo,代码行数:25,代码来源:storage_options.cpp

示例2: invariant

KVCatalog::FeatureTracker::FeatureBits KVCatalog::FeatureTracker::getInfo(
    OperationContext* opCtx) const {
    if (_rid.isNull()) {
        return {};
    }

    auto record = _catalog->_rs->dataFor(opCtx, _rid);
    BSONObj obj = record.toBson();
    invariant(isFeatureDocument(obj));

    BSONElement nonRepairableFeaturesElem;
    auto nonRepairableFeaturesStatus = bsonExtractTypedField(
        obj, kNonRepairableFeaturesFieldName, BSONType::NumberLong, &nonRepairableFeaturesElem);
    fassert(40111, nonRepairableFeaturesStatus);

    BSONElement repairableFeaturesElem;
    auto repairableFeaturesStatus = bsonExtractTypedField(
        obj, kRepairableFeaturesFieldName, BSONType::NumberLong, &repairableFeaturesElem);
    fassert(40112, repairableFeaturesStatus);

    FeatureBits versionInfo;
    versionInfo.nonRepairableFeatures =
        static_cast<NonRepairableFeatureMask>(nonRepairableFeaturesElem.numberLong());
    versionInfo.repairableFeatures =
        static_cast<RepairableFeatureMask>(repairableFeaturesElem.numberLong());
    return versionInfo;
}
开发者ID:zhihuiFan,项目名称:mongo,代码行数:27,代码来源:kv_catalog.cpp

示例3: applySkipLimit

    static long long applySkipLimit(long long num, const BSONObj& cmd) {
        BSONElement s = cmd["skip"];
        BSONElement l = cmd["limit"];

        if (s.isNumber()) {
            num = num - s.numberLong();
            if (num < 0) {
                num = 0;
            }
        }

        if (l.isNumber()) {
            long long limit = l.numberLong();
            if (limit < 0) {
                limit = -limit;
            }

            // 0 means no limit.
            if (limit < num && limit != 0) {
                num = limit;
            }
        }

        return num;
    }
开发者ID:FromPointer,项目名称:mongo,代码行数:25,代码来源:count.cpp

示例4: compareNumbers

int compareNumbers(const BSONElement& lhs, const BSONElement& rhs) {
    invariant(lhs.isNumber());
    invariant(rhs.isNumber());

    if (lhs.type() == NumberInt || lhs.type() == NumberLong) {
        if (rhs.type() == NumberInt || rhs.type() == NumberLong) {
            return COMPARE_HELPER(lhs.numberLong(), rhs.numberLong());
        }
        return compareLongToDouble(lhs.numberLong(), rhs.Double());
    } else {  // double
        if (rhs.type() == NumberDouble) {
            return COMPARE_HELPER(lhs.Double(), rhs.Double());
        }
        return -compareLongToDouble(rhs.numberLong(), lhs.Double());
    }
}
开发者ID:kangic,项目名称:mongo,代码行数:16,代码来源:key_string_test.cpp

示例5: isCursorCommand

    static bool isCursorCommand(BSONObj cmdObj) {
        BSONElement cursorElem = cmdObj["cursor"];
        if (cursorElem.eoo())
            return false;

        uassert(16954, "cursor field must be missing or an object",
                cursorElem.type() == Object);

        BSONObj cursor = cursorElem.embeddedObject();
        BSONElement batchSizeElem = cursor["batchSize"];
        if (batchSizeElem.eoo()) {
            uassert(16955, "cursor object can't contain fields other than batchSize",
                cursor.isEmpty());
        }
        else {
            uassert(16956, "cursor.batchSize must be a number",
                    batchSizeElem.isNumber());

            // This can change in the future, but for now all negatives are reserved.
            uassert(16957, "Cursor batchSize must not be negative",
                    batchSizeElem.numberLong() >= 0);
        }

        return true;
    }
开发者ID:Frendzel,项目名称:mongo,代码行数:25,代码来源:pipeline_command.cpp

示例6: create

intrusive_ptr<DocumentSource> DocumentSourceLimit::createFromBson(
    BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) {
    uassert(15957, "the limit must be specified as a number", elem.isNumber());

    long long limit = elem.numberLong();
    return DocumentSourceLimit::create(pExpCtx, limit);
}
开发者ID:hgGeorg,项目名称:mongo,代码行数:7,代码来源:document_source_limit.cpp

示例7: init

 INT32 _omaHandleTaskNotify::init ( const CHAR *pInstallInfo )
 {
    INT32 rc      = SDB_OK ;
    UINT64 taskID = 0 ;
    BSONObj obj ;
    BSONElement ele ;
    try
    {
       obj = BSONObj( pInstallInfo ).copy() ;
       ele = obj.getField( OMA_FIELD_TASKID ) ;
       if ( NumberInt != ele.type() && NumberLong != ele.type() )
       {
          PD_LOG_MSG ( PDERROR, "Receive invalid task id from omsvc" ) ;
          rc = SDB_INVALIDARG ;
          goto error ;
       }
       taskID = ele.numberLong() ;
       _taskIDObj = BSON( OMA_FIELD_TASKID << (INT64)taskID ) ;
       
    }
    catch ( std::exception &e )
    {
       rc = SDB_INVALIDARG ;
       PD_LOG ( PDERROR, "Failed to build bson, exception is: %s",
                e.what() ) ;
       goto error ;
    }
    
 done:
    return rc ;
 error :
    goto done ;
 }
开发者ID:BryanLance,项目名称:SequoiaDB,代码行数:33,代码来源:omagentSyncCmd.cpp

示例8: move

StatusWith<long long> retrieveTotalShardSize(OperationContext* opCtx, const ShardId& shardId) {
    auto shardStatus = Grid::get(opCtx)->shardRegistry()->getShard(opCtx, shardId);
    if (!shardStatus.isOK()) {
        return shardStatus.getStatus();
    }

    // Since 'listDatabases' is potentially slow in the presence of large number of collections, use
    // a higher maxTimeMS to prevent it from prematurely timing out
    const Minutes maxTimeMSOverride{10};

    auto listDatabasesStatus = shardStatus.getValue()->runCommandWithFixedRetryAttempts(
        opCtx,
        ReadPreferenceSetting{ReadPreference::PrimaryPreferred},
        "admin",
        BSON("listDatabases" << 1),
        maxTimeMSOverride,
        Shard::RetryPolicy::kIdempotent);

    if (!listDatabasesStatus.isOK()) {
        return std::move(listDatabasesStatus.getStatus());
    }

    if (!listDatabasesStatus.getValue().commandStatus.isOK()) {
        return std::move(listDatabasesStatus.getValue().commandStatus);
    }

    BSONElement totalSizeElem = listDatabasesStatus.getValue().response["totalSize"];
    if (!totalSizeElem.isNumber()) {
        return {ErrorCodes::NoSuchKey, "totalSize field not found in listDatabases"};
    }

    return totalSizeElem.numberLong();
}
开发者ID:DINKIN,项目名称:mongo,代码行数:33,代码来源:shard_util.cpp

示例9: Status

StatusWith<long long> retrieveTotalShardSize(OperationContext* txn, const ShardId& shardId) {
    auto shard = Grid::get(txn)->shardRegistry()->getShard(txn, shardId);
    if (!shard) {
        return Status(ErrorCodes::ShardNotFound,
                      str::stream() << "shard " << shardId << " not found");
    }
    auto listDatabasesStatus =
        shard->runCommand(txn,
                          ReadPreferenceSetting{ReadPreference::PrimaryPreferred},
                          "admin",
                          BSON("listDatabases" << 1),
                          Shard::RetryPolicy::kIdempotent);
    if (!listDatabasesStatus.isOK()) {
        return std::move(listDatabasesStatus.getStatus());
    }
    if (!listDatabasesStatus.getValue().commandStatus.isOK()) {
        return std::move(listDatabasesStatus.getValue().commandStatus);
    }

    BSONElement totalSizeElem = listDatabasesStatus.getValue().response["totalSize"];
    if (!totalSizeElem.isNumber()) {
        return {ErrorCodes::NoSuchKey, "totalSize field not found in listDatabases"};
    }

    return totalSizeElem.numberLong();
}
开发者ID:ChineseDr,项目名称:mongo,代码行数:26,代码来源:shard_util.cpp

示例10: init

   INT32 _rtnCancelTask::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 matcher( pMatcherBuff ) ;
         BSONElement ele = matcher.getField( CAT_TASKID_NAME ) ;
         if ( ele.eoo() || !ele.isNumber() )
         {
            PD_LOG( PDERROR, "Field[%s] type[%d] is error", CAT_TASKID_NAME,
                    ele.type() ) ;
            rc = SDB_INVALIDARG ;
            goto error ;
         }
         _taskID = (UINT64)ele.numberLong() ;
      }
      catch ( std::exception &e )
      {
         PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

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

示例11:

// static
StatusWith<BSONObj> S2AccessMethod::fixSpec(const BSONObj& specObj) {
    // If the spec object has the field "2dsphereIndexVersion", validate it.  If it doesn't, add
    // {2dsphereIndexVersion: 3}, which is the default for newly-built indexes.

    BSONElement indexVersionElt = specObj[kIndexVersionFieldName];
    if (indexVersionElt.eoo()) {
        BSONObjBuilder bob;
        bob.appendElements(specObj);
        bob.append(kIndexVersionFieldName, S2_INDEX_VERSION_3);
        return bob.obj();
    }

    if (!indexVersionElt.isNumber()) {
        return {ErrorCodes::CannotCreateIndex,
                str::stream() << "Invalid type for geo index version { " << kIndexVersionFieldName
                              << " : "
                              << indexVersionElt
                              << " }, only versions: ["
                              << S2_INDEX_VERSION_1
                              << ","
                              << S2_INDEX_VERSION_2
                              << ","
                              << S2_INDEX_VERSION_3
                              << "] are supported"};
    }

    if (indexVersionElt.type() == BSONType::NumberDouble &&
        !std::isnormal(indexVersionElt.numberDouble())) {
        return {ErrorCodes::CannotCreateIndex,
                str::stream() << "Invalid value for geo index version { " << kIndexVersionFieldName
                              << " : "
                              << indexVersionElt
                              << " }, only versions: ["
                              << S2_INDEX_VERSION_1
                              << ","
                              << S2_INDEX_VERSION_2
                              << ","
                              << S2_INDEX_VERSION_3
                              << "] are supported"};
    }

    const auto indexVersion = indexVersionElt.numberLong();
    if (indexVersion != S2_INDEX_VERSION_1 && indexVersion != S2_INDEX_VERSION_2 &&
        indexVersion != S2_INDEX_VERSION_3) {
        return {ErrorCodes::CannotCreateIndex,
                str::stream() << "unsupported geo index version { " << kIndexVersionFieldName
                              << " : "
                              << indexVersionElt
                              << " }, only versions: ["
                              << S2_INDEX_VERSION_1
                              << ","
                              << S2_INDEX_VERSION_2
                              << ","
                              << S2_INDEX_VERSION_3
                              << "] are supported"};
    }

    return specObj;
}
开发者ID:Tsmith5151,项目名称:mongo,代码行数:60,代码来源:s2_access_method.cpp

示例12: handleCursorCommand

    static void handleCursorCommand(CursorId id, BSONObj& cmdObj, BSONObjBuilder& result) {
        BSONElement batchSizeElem = cmdObj.getFieldDotted("cursor.batchSize");
        const long long batchSize = batchSizeElem.isNumber()
                                    ? batchSizeElem.numberLong()
                                    : 101; // same as query

        ClientCursorPin pin(id);
        ClientCursor* cursor = pin.c();

        massert(16958, "Cursor shouldn't have been deleted",
                cursor);

        verify(cursor->isAggCursor);
        PipelineRunner* runner = dynamic_cast<PipelineRunner*>(cursor->getRunner());
        verify(runner);
        try {
            const string cursorNs = cursor->ns(); // we need this after cursor may have been deleted

            // can't use result BSONObjBuilder directly since it won't handle exceptions correctly.
            BSONArrayBuilder resultsArray;
            const int byteLimit = MaxBytesToReturnToClientAtOnce;
            BSONObj next;
            for (int objCount = 0; objCount < batchSize; objCount++) {
                // The initial getNext() on a PipelineRunner may be very expensive so we don't do it
                // when batchSize is 0 since that indicates a desire for a fast return.
                if (runner->getNext(&next, NULL) != Runner::RUNNER_ADVANCED) {
                    pin.deleteUnderlying();
                    id = 0;
                    cursor = NULL; // make it an obvious error to use cursor after this point
                    break;
                }

                if (resultsArray.len() + next.objsize() > byteLimit) {
                    // too big. next will be the first doc in the second batch
                    runner->pushBack(next);
                    break;
                }

                resultsArray.append(next);
            }

            if (cursor) {
                // If a time limit was set on the pipeline, remaining time is "rolled over" to the
                // cursor (for use by future getmore ops).
                cursor->setLeftoverMaxTimeMicros( cc().curop()->getRemainingMaxTimeMicros() );
            }

            BSONObjBuilder cursorObj(result.subobjStart("cursor"));
            cursorObj.append("id", id);
            cursorObj.append("ns", cursorNs);
            cursorObj.append("firstBatch", resultsArray.arr());
            cursorObj.done();
        }
        catch (...) {
            // Clean up cursor on way out of scope.
            pin.deleteUnderlying();
            throw;
        }
    }
开发者ID:DanilSerd,项目名称:mongo,代码行数:59,代码来源:pipeline_command.cpp

示例13: reload

        void reload() {

            list<BSONObj> all;
            {
                ScopedDbConnection conn( configServer.getPrimary() );
                auto_ptr<DBClientCursor> c = conn->query( ShardNS::shard , Query() );
                massert( 13632 , "couldn't get updated shard list from config server" , c.get() );
                while ( c->more() ) {
                    all.push_back( c->next().getOwned() );
                }
                conn.done();
            }

            scoped_lock lk( _mutex );

            // We use the _lookup table for all shards and for the primary config DB. The config DB info,
            // however, does not come from the ShardNS::shard. So when cleaning the _lookup table we leave
            // the config state intact. The rationale is that this way we could drop shards that
            // were removed without reinitializing the config DB information.

            map<string,Shard>::iterator i = _lookup.find( "config" );
            if ( i != _lookup.end() ) {
                Shard config = i->second;
                _lookup.clear();
                _lookup[ "config" ] = config;
            }
            else {
                _lookup.clear();
            }

            for ( list<BSONObj>::iterator i=all.begin(); i!=all.end(); ++i ) {
                BSONObj o = *i;
                string name = o["_id"].String();
                string host = o["host"].String();

                long long maxSize = 0;
                BSONElement maxSizeElem = o[ ShardFields::maxSize.name() ];
                if ( ! maxSizeElem.eoo() ) {
                    maxSize = maxSizeElem.numberLong();
                }

                bool isDraining = false;
                BSONElement isDrainingElem = o[ ShardFields::draining.name() ];
                if ( ! isDrainingElem.eoo() ) {
                    isDraining = isDrainingElem.Bool();
                }

                Shard s( name , host , maxSize , isDraining );
                _lookup[name] = s;
                _lookup[host] = s;

                // add rs name to lookup (if it exists)
                size_t pos;
                if ((pos = host.find('/', 0)) != string::npos) {
                    _lookup[host.substr(0, pos)] = s;
                }
            }

        }
开发者ID:adrien-mogenet,项目名称:mongo,代码行数:59,代码来源:shard.cpp

示例14: _fromBson

   INT32 dpsArchiveInfoMgr::_fromBson( const BSONObj& data,
                                       dpsArchiveInfo& info,
                                       INT64& count )
   {
      INT32 rc = SDB_OK ;
      BSONElement ele ;
      dpsArchiveInfo _info ;
      INT64 _count = 0 ;

      ele = data.getField( DPS_ARCHIVE_INFO_COUNTER ) ;
      if ( NumberLong != ele.type() && NumberInt != ele.type() )
      {
         rc = SDB_INVALIDARG ;
         goto error ;
      }
      _count = ele.numberLong() ;
      if ( _count <= 0 )
      {
         rc = SDB_INVALIDARG ;
         goto error ;
      }

      ele = data.getField( DPS_ARCHIVE_INFO_NEXTLSN ) ;
      if ( NumberLong != ele.type() && NumberInt != ele.type() )
      {
         rc = SDB_INVALIDARG ;
         goto error ;
      }
      _info.startLSN.offset = ele.numberLong() ;
      if ( _info.startLSN.offset == DPS_INVALID_LSN_OFFSET )
      {
         rc = SDB_INVALIDARG ;
         goto error ;
      }

      info = _info ;
      count = _count ;

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

示例15: create

intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson(
    BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) {
    uassert(15972,
            str::stream() << "Argument to $skip must be a number not a " << typeName(elem.type()),
            elem.isNumber());
    auto nToSkip = elem.numberLong();
    uassert(15956, "Argument to $skip cannot be negative", nToSkip >= 0);

    return DocumentSourceSkip::create(pExpCtx, nToSkip);
}
开发者ID:Machyne,项目名称:mongo,代码行数:10,代码来源:document_source_skip.cpp


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