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


C++ BSONArrayBuilder类代码示例

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


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

示例1: combineWCErrors

    // Aggregate all WC errors for the whole batch into a single error
    static void combineWCErrors( const vector<ShardError*>& wcResponses,
                                 BatchedErrorDetail* error ) {

        // Special case, pass through details of single error for better usability
        if ( wcResponses.size() == 1 ) {
            wcResponses.front()->error.cloneTo( error );
            return;
        }

        error->setErrCode( ErrorCodes::WriteConcernFailed );

        // Generate the multi-error message below
        stringstream msg;
        msg << "multiple errors reported : ";

        BSONArrayBuilder errB;
        for ( vector<ShardError*>::const_iterator it = wcResponses.begin(); it != wcResponses.end();
            ++it ) {
            const ShardError* wcError = *it;
            if ( it != wcResponses.begin() ) msg << " :: and :: ";
            msg << wcError->error.getErrMessage();
            errB.append( wcError->error.getErrInfo() );
        }

        error->setErrInfo( BSON( "info" << errB.arr() ) );
        error->setErrMessage( msg.str() );
    }
开发者ID:hipsterbd,项目名称:mongo,代码行数:28,代码来源:batch_write_op.cpp

示例2: run

        virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
            string p = cmdObj.firstElement().String();
            if ( p == "*" ) {
                vector<string> names;
                RamLog::getNames( names );

                BSONArrayBuilder arr;
                for ( unsigned i=0; i<names.size(); i++ ) {
                    arr.append( names[i] );
                }
                
                result.appendArray( "names" , arr.arr() );
            }
            else {
                RamLog* ramlog = RamLog::getIfExists(p);
                if ( ! ramlog ) {
                    errmsg = str::stream() << "no RamLog named: " << p;
                    return false;
                }
                RamLog::LineIterator rl(ramlog);

                result.appendNumber( "totalLinesWritten", rl.getTotalLinesWritten() );

                BSONArrayBuilder arr( result.subarrayStart( "log" ) );
                while (rl.more())
                    arr.append(rl.next());
                arr.done();
            }
            return true;
        }
开发者ID:leeon,项目名称:mongo,代码行数:30,代码来源:dbcommands_generic.cpp

示例3: runApplyOpsCmd

Status runApplyOpsCmd(OperationContext* txn,
                      const std::vector<ChunkType>& chunksToMerge,
                      const ChunkVersion& currShardVersion,
                      const ChunkVersion& newMergedVersion) {
    BSONArrayBuilder updatesB;

    // The chunk we'll be "expanding" is the first chunk
    const ChunkType& firstChunk = chunksToMerge.front();

    // Fill in details not tracked by metadata
    ChunkType mergedChunk(firstChunk);
    mergedChunk.setName(ChunkType::genID(firstChunk.getNS(), firstChunk.getMin()));
    mergedChunk.setMax(chunksToMerge.back().getMax());
    mergedChunk.setVersion(newMergedVersion);

    updatesB.append(buildOpMergeChunk(mergedChunk));

    // Don't remove chunk we're expanding
    for (size_t i = 1; i < chunksToMerge.size(); ++i) {
        ChunkType chunkToMerge(chunksToMerge[i]);
        chunkToMerge.setName(ChunkType::genID(chunkToMerge.getNS(), chunkToMerge.getMin()));
        updatesB.append(buildOpRemoveChunk(chunkToMerge));
    }

    BSONArray preCond = buildOpPrecond(firstChunk.getNS(), firstChunk.getShard(), currShardVersion);

    return grid.catalogManager(txn)->applyChunkOpsDeprecated(
        txn, updatesB.arr(), preCond, firstChunk.getNS(), newMergedVersion);
}
开发者ID:NikolaySt,项目名称:mongo,代码行数:29,代码来源:d_merge.cpp

示例4: writeMetadataFile

    void writeMetadataFile( const string coll, boost::filesystem::path outputFile, 
                            map<string, BSONObj> options, multimap<string, BSONObj> indexes ) {
        toolInfoLog() << "\tMetadata for " << coll << " to " << outputFile.string() << std::endl;

        bool hasOptions = options.count(coll) > 0;
        bool hasIndexes = indexes.count(coll) > 0;

        BSONObjBuilder metadata;

        if (hasOptions) {
            metadata << "options" << options.find(coll)->second;
        }

        if (hasIndexes) {
            BSONArrayBuilder indexesOutput (metadata.subarrayStart("indexes"));

            // I'd kill for C++11 auto here...
            const pair<multimap<string, BSONObj>::iterator, multimap<string, BSONObj>::iterator>
                range = indexes.equal_range(coll);

            for (multimap<string, BSONObj>::iterator it=range.first; it!=range.second; ++it) {
                 indexesOutput << it->second;
            }

            indexesOutput.done();
        }

        ofstream file (outputFile.string().c_str());
        uassert(15933, "Couldn't open file: " + outputFile.string(), file.is_open());
        file << metadata.done().jsonString();
    }
开发者ID:ANTco,项目名称:mongo,代码行数:31,代码来源:dump.cpp

示例5: checkIfUp

mongo::BSONArray MockRemoteDBServer::query(MockRemoteDBServer::InstanceID id,
                                           const string& ns,
                                           mongo::Query query,
                                           int nToReturn,
                                           int nToSkip,
                                           const BSONObj* fieldsToReturn,
                                           int queryOptions,
                                           int batchSize) {
    checkIfUp(id);

    if (_delayMilliSec > 0) {
        mongo::sleepmillis(_delayMilliSec);
    }

    checkIfUp(id);

    scoped_spinlock sLock(_lock);
    _queryCount++;

    const vector<BSONObj>& coll = _dataMgr[ns];
    BSONArrayBuilder result;
    for (vector<BSONObj>::const_iterator iter = coll.begin(); iter != coll.end(); ++iter) {
        result.append(iter->copy());
    }

    return BSONArray(result.obj());
}
开发者ID:Andiry,项目名称:mongo,代码行数:27,代码来源:mock_remote_db_server.cpp

示例6: run

        bool run(OperationContext* txn,
                 const string& dbname,
                 BSONObj& jsobj,
                 int,
                 string& errmsg,
                 BSONObjBuilder& result,
                 bool /*fromRepl*/) {

            Client::ReadContext ctx( txn, dbname );
            const Database* d = ctx.ctx().db();
            const DatabaseCatalogEntry* dbEntry = d->getDatabaseCatalogEntry();

            list<string> names;
            dbEntry->getCollectionNamespaces( &names );

            BSONArrayBuilder arr;

            for ( list<string>::const_iterator i = names.begin(); i != names.end(); ++i ) {
                string ns = *i;

                BSONObjBuilder b;
                b.append( "name", nsToCollectionSubstring( ns ) );

                CollectionOptions options =
                    dbEntry->getCollectionCatalogEntry( txn, ns )->getCollectionOptions(txn);
                b.append( "options", options.toBSON() );

                arr.append( b.obj() );
            }

            result.append( "collections", arr.arr() );

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

示例7: onCommandWithMetadata

void NetworkTestEnv::onFindWithMetadataCommand(OnFindCommandWithMetadataFunction func) {
    onCommandWithMetadata([&func](const RemoteCommandRequest& request) -> RemoteCommandResponse {
        const auto& resultStatus = func(request);

        if (!resultStatus.isOK()) {
            return resultStatus.getStatus();
        }

        std::vector<BSONObj> result;
        BSONObj metadata;
        std::tie(result, metadata) = resultStatus.getValue();

        BSONArrayBuilder arr;
        for (const auto& obj : result) {
            arr.append(obj);
        }

        const NamespaceString nss =
            NamespaceString(request.dbname, request.cmdObj.firstElement().String());
        BSONObjBuilder resultBuilder;
        appendCursorResponseObject(0LL, nss.toString(), arr.arr(), &resultBuilder);

        return RemoteCommandResponse(resultBuilder.obj(), metadata, Milliseconds(1));
    });
}
开发者ID:ChineseDr,项目名称:mongo,代码行数:25,代码来源:network_test_env.cpp

示例8: BSON

void CMISProductNotificationAPI::Convert2JSON(CNotificationModel* pData, BSONObj &boRecord)
{
	//{"data":[{"request_code":"RP130314/004","operation_department":"BO6"}],"source":"SDK"}
	BSONArrayBuilder babElement;
	BSONObjBuilder bobProductInfo;
	map<string, string>::iterator mit;
	map<string, string> mapAPIField;
	mapAPIField["department_alias"] = "operation_department";
	mapAPIField["request_code"] = "request_code";

	BSONObj boTemp = *pData;
	for (mit = mapAPIField.begin(); mit != mapAPIField.end(); mit++)
	{
		if (boTemp.hasField(mit->first)){
			bobProductInfo.append(mit->second, boTemp.getStringField(mit->first.c_str()));
		}
		else{
			bobProductInfo.append(mit->second, "");
		}
	}

	babElement << bobProductInfo.obj();
	boRecord = BSON(
		"data" << babElement.arr() <<
		"source" << "SDK"
		);
}
开发者ID:fr34k8,项目名称:CMDBv2,代码行数:27,代码来源:MISProductNotificationAPI.cpp

示例9: while

int64_t RecordStoreV1Base::storageSize(OperationContext* txn,
                                       BSONObjBuilder* extraInfo,
                                       int level) const {
    BSONArrayBuilder extentInfo;

    int64_t total = 0;
    int n = 0;

    DiskLoc cur = _details->firstExtent(txn);

    while (!cur.isNull()) {
        Extent* e = _extentManager->getExtent(cur);

        total += e->length;
        n++;

        if (extraInfo && level > 0) {
            extentInfo.append(BSON("len" << e->length << "loc: " << e->myLoc.toBSONObj()));
        }
        cur = e->xnext;
    }

    if (extraInfo) {
        extraInfo->append("numExtents", n);
        if (level > 0)
            extraInfo->append("extents", extentInfo.arr());
    }

    return total;
}
开发者ID:AnkyrinRepeat,项目名称:mongo,代码行数:30,代码来源:record_store_v1_base.cpp

示例10: GetListUserGroupsProducts

BSONArray CAdminUserGroupsProductsController::GetListUserGroupsProducts(auto_ptr<DBClientCursor>& ptrCursor, const string &strProductCode)
{
	BSONArrayBuilder baGroupProduct;
	BSONObj boRecord;
	
	if (FindOperatingUserGroupByProduct(ptrCursor, strProductCode))
	{
		try
		{
			while(ptrCursor->more())
			{
				boRecord = ptrCursor->nextSafe();
				baGroupProduct << boRecord["user_group_id"];
			}
		}
		catch(exception& ex)
		{	
			stringstream strErrorMess;
			string strLog;
			strErrorMess << ex.what() << "][" << __FILE__ << "|" << __LINE__ ;
			strLog = CUtilities::FormatLog(ERROR_MSG, "CAdminUserGroupsProductsController", "GetListUserGroupsProducts","Exception:" + strErrorMess.str());
			CUtilities::WriteErrorLog(ERROR_MSG, strLog);
		}
	}
	return baGroupProduct.arr();
}
开发者ID:fr34k8,项目名称:CMDBv2,代码行数:26,代码来源:AdminUserGroupsProductsController.cpp

示例11: getServiceContext

void ShardingMongodTestFixture::setUp() {
    ServiceContextMongoDTest::setUp();

    auto serviceContext = getServiceContext();
    _opCtx = cc().makeOperationContext();

    // Set up this node as part of a replica set.

    repl::ReplSettings replSettings;
    replSettings.setReplSetString(ConnectionString::forReplicaSet(_setName, _servers).toString());
    auto replCoordPtr = makeReplicationCoordinator(replSettings);
    _replCoord = replCoordPtr.get();

    BSONArrayBuilder serversBob;
    for (size_t i = 0; i < _servers.size(); ++i) {
        serversBob.append(BSON("host" << _servers[i].toString() << "_id" << static_cast<int>(i)));
    }
    repl::ReplicaSetConfig replSetConfig;
    replSetConfig.initialize(BSON("_id" << _setName << "protocolVersion" << 1 << "version" << 3
                                        << "members"
                                        << serversBob.arr()));
    replCoordPtr->setGetConfigReturnValue(replSetConfig);

    repl::ReplicationCoordinator::set(serviceContext, std::move(replCoordPtr));

    serviceContext->setOpObserver(stdx::make_unique<OpObserverImpl>());
    repl::setOplogCollectionName();
    repl::createOplog(_opCtx.get());
}
开发者ID:ksuarz,项目名称:mongo,代码行数:29,代码来源:sharding_mongod_test_fixture.cpp

示例12: run

        virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
            string p = cmdObj.firstElement().String();
            if ( p == "*" ) {
                vector<string> names;
                RamLog::getNames( names );

                BSONArrayBuilder arr;
                for ( unsigned i=0; i<names.size(); i++ ) {
                    arr.append( names[i] );
                }
                
                result.appendArray( "names" , arr.arr() );
            }
            else {
                RamLog* rl = RamLog::get( p );
                if ( ! rl ) {
                    errmsg = str::stream() << "no RamLog named: " << p;
                    return false;
                }

                result.appendNumber( "totalLinesWritten", rl->getTotalLinesWritten() );

                vector<const char*> lines;
                rl->get( lines );

                BSONArrayBuilder arr( result.subarrayStart( "log" ) );
                for ( unsigned i=0; i<lines.size(); i++ )
                    arr.append( lines[i] );
                arr.done();
            }
            return true;
        }
开发者ID:NathanZamecnik,项目名称:mongo,代码行数:32,代码来源:dbcommands_generic.cpp

示例13: getErrorLabels

BSONObj getErrorLabels(const OperationSessionInfoFromClient& sessionOptions,
                       const std::string& commandName,
                       ErrorCodes::Error code,
                       bool hasWriteConcernError) {
    BSONArrayBuilder labelArray;

    // Note that we only apply the TransientTxnError label if the "autocommit" field is present in
    // the session options. When present, "autocommit" will always be false, so we don't check its
    // value.
    if (sessionOptions.getAutocommit() &&
        isTransientTransactionError(code,
                                    hasWriteConcernError,
                                    commandName == "commitTransaction" ||
                                        commandName == "coordinateCommitTransaction")) {
        // An error code for which isTransientTransactionError() is true indicates a transaction
        // failure with no persistent side effects.
        labelArray << txn::TransientTxnErrorFieldName;
    }

    if (ErrorCodes::isNonResumableChangeStreamError(code)) {
        labelArray << "NonResumableChangeStreamError";
    }

    return (labelArray.arrSize() > 0) ? BSON("errorLabels" << labelArray.arr()) : BSONObj();
}
开发者ID:guoyr,项目名称:mongo,代码行数:25,代码来源:handle_request_response.cpp

示例14: toBson

    void Pipeline::toBson(BSONObjBuilder *pBuilder) const {
        /* create an array out of the pipeline operations */
        BSONArrayBuilder arrayBuilder;
        for(SourceContainer::const_iterator iter(sources.begin()),
                                            listEnd(sources.end());
                                        iter != listEnd;
                                        ++iter) {
            intrusive_ptr<DocumentSource> pSource(*iter);
            pSource->addToBsonArray(&arrayBuilder);
        }

        /* add the top-level items to the command */
        pBuilder->append(commandName, getCollectionName());
        pBuilder->append(pipelineName, arrayBuilder.arr());

        if (explain) {
            pBuilder->append(explainName, explain);
        }

        bool btemp;
        if ((btemp = getSplitMongodPipeline())) {
            pBuilder->append(splitMongodPipelineName, btemp);
        }

        if ((btemp = pCtx->getInRouter())) {
            pBuilder->append(fromRouterName, btemp);
        }
    }
开发者ID:darkiri,项目名称:mongo,代码行数:28,代码来源:pipeline.cpp

示例15: writeString

 void DocumentSource::writeString(stringstream &ss) const {
     BSONArrayBuilder bab;
     addToBsonArray(&bab);
     BSONArray ba(bab.arr());
     ss << ba.toString(/* isArray */true); 
         // our toString should use standard string types.....
 }
开发者ID:nosqldb,项目名称:mongo,代码行数:7,代码来源:document_source.cpp


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