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


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

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


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

示例1: prepareReplSetUpdatePositionCommandHandshakes

    void LegacyReplicationCoordinator::prepareReplSetUpdatePositionCommandHandshakes(
            OperationContext* txn,
            std::vector<BSONObj>* handshakes) {
        invariant(getReplicationMode() == modeReplSet);
        boost::lock_guard<boost::mutex> lock(_mutex);
        // handshake obj for us
        BSONObjBuilder cmd;
        cmd.append("replSetUpdatePosition", 1);
        BSONObjBuilder sub (cmd.subobjStart("handshake"));
        sub.append("handshake", getMyRID(txn));
        sub.append("member", theReplSet->selfId());
        sub.append("config", theReplSet->myConfig().asBson());
        sub.doneFast();
        handshakes->push_back(cmd.obj());

        // handshake objs for all chained members
        for (OIDMemberMap::const_iterator itr = _ridMemberMap.begin();
             itr != _ridMemberMap.end(); ++itr) {
            BSONObjBuilder cmd;
            cmd.append("replSetUpdatePosition", 1);
            // outer handshake indicates this is a handshake command
            // inner is needed as part of the structure to be passed to gotHandshake
            BSONObjBuilder subCmd (cmd.subobjStart("handshake"));
            subCmd.append("handshake", itr->first);
            subCmd.append("member", itr->second->id());
            subCmd.append("config", itr->second->config().asBson());
            subCmd.doneFast();
            handshakes->push_back(cmd.obj());
        }
    }
开发者ID:QiangTimer,项目名称:mongo,代码行数:30,代码来源:repl_coordinator_legacy.cpp

示例2: addToBsonArray

    void DocumentSourceSort::addToBsonArray(BSONArrayBuilder *pBuilder, bool explain) const {
        if (explain) { // always one obj for combined $sort + $limit
            BSONObjBuilder sortObj (pBuilder->subobjStart());
            BSONObjBuilder insides (sortObj.subobjStart(sortName));
            BSONObjBuilder sortKey (insides.subobjStart("sortKey"));
            sortKeyToBson(&sortKey, false);
            sortKey.doneFast();

            if (explain && limitSrc) {
                insides.appendNumber("limit", limitSrc->getLimit());
            }
            insides.doneFast();
            sortObj.doneFast();
        }
        else { // one obj for $sort + maybe one obj for $limit
            {
                BSONObjBuilder sortObj (pBuilder->subobjStart());
                BSONObjBuilder insides (sortObj.subobjStart(sortName));
                sortKeyToBson(&insides, false);
                insides.doneFast();
                sortObj.doneFast();
            }

            if (limitSrc) {
                limitSrc->addToBsonArray(pBuilder, explain);
            }
        }
    }
开发者ID:IanWhalen,项目名称:mongo,代码行数:28,代码来源:document_source_sort.cpp

示例3: sourceToBson

    void DocumentSourceGeoNear::sourceToBson(BSONObjBuilder *pBuilder, bool explain) const {
        BSONObjBuilder geoNear (pBuilder->subobjStart("$geoNear"));

        if (coordsIsArray) {
            geoNear.appendArray("near", coords);
        }
        else {
            geoNear.append("near", coords);
        }

        geoNear.append("distanceField", distanceField->getPath(false)); // not in buildGeoNearCmd
        geoNear.append("limit", limit);

        if (maxDistance > 0)
            geoNear.append("maxDistance", maxDistance);

        geoNear.append("query", query);
        geoNear.append("spherical", spherical);
        geoNear.append("distanceMultiplier", distanceMultiplier);

        if (includeLocs)
            geoNear.append("includeLocs", includeLocs->getPath(false));

        geoNear.append("uniqueDocs", uniqueDocs);

        geoNear.doneFast();
    }
开发者ID:DjComandos,项目名称:mongo,代码行数:27,代码来源:document_source_geo_near.cpp

示例4: run

    bool Pipeline::run(BSONObjBuilder &result, string &errmsg) {
        massert(16600, "should not have an empty pipeline",
                !sources.empty());

        /* chain together the sources we found */
        DocumentSource* prevSource = sources.front().get();
        for(SourceContainer::iterator iter(sources.begin() + 1),
                                      listEnd(sources.end());
                                    iter != listEnd;
                                    ++iter) {
            intrusive_ptr<DocumentSource> pTemp(*iter);
            pTemp->setSource(prevSource);
            prevSource = pTemp.get();
        }

        /*
          Iterate through the resulting documents, and add them to the result.
          We do this even if we're doing an explain, in order to capture
          the document counts and other stats.  However, we don't capture
          the result documents for explain.
        */
        if (explain) {
            if (!pCtx->getInRouter())
                writeExplainShard(result);
            else {
                writeExplainMongos(result);
            }
        }
        else {
            // the array in which the aggregation results reside
            // cant use subArrayStart() due to error handling
            BSONArrayBuilder resultArray;
            DocumentSource* finalSource = sources.back().get();
            for(bool hasDoc = !finalSource->eof(); hasDoc; hasDoc = finalSource->advance()) {
                Document pDocument(finalSource->getCurrent());

                /* add the document to the result set */
                BSONObjBuilder documentBuilder (resultArray.subobjStart());
                pDocument->toBson(&documentBuilder);
                documentBuilder.doneFast();
                // object will be too large, assert. the extra 1KB is for headers
                uassert(16389,
                        str::stream() << "aggregation result exceeds maximum document size ("
                                      << BSONObjMaxUserSize / (1024 * 1024) << "MB)",
                        resultArray.len() < BSONObjMaxUserSize - 1024);
            }

            resultArray.done();
            result.appendArray("result", resultArray.arr());
        }

    return true;
    }
开发者ID:darkiri,项目名称:mongo,代码行数:53,代码来源:pipeline.cpp

示例5: _makeCmd

BSONObj ClusterCommandTestFixture::_makeCmd(BSONObj cmdObj, bool includeAfterClusterTime) {
    BSONObjBuilder bob(cmdObj);
    // Each command runs in a new session.
    bob.append("lsid", makeLogicalSessionIdForTest().toBSON());
    bob.append("txnNumber", TxnNumber(1));
    bob.append("autocommit", false);
    bob.append("startTransaction", true);

    BSONObjBuilder readConcernBob = bob.subobjStart(repl::ReadConcernArgs::kReadConcernFieldName);
    readConcernBob.append("level", "snapshot");
    if (includeAfterClusterTime) {
        readConcernBob.append("afterClusterTime", kAfterClusterTime);
    }

    readConcernBob.doneFast();
    return bob.obj();
}
开发者ID:hanumantmk,项目名称:mongo,代码行数:17,代码来源:cluster_command_test_fixture.cpp

示例6: run

    void Pipeline::run(BSONObjBuilder& result) {
        /*
          Iterate through the resulting documents, and add them to the result.
          We do this even if we're doing an explain, in order to capture
          the document counts and other stats.  However, we don't capture
          the result documents for explain.
        */
        if (explain) {
            if (!pCtx->getInRouter())
                writeExplainShard(result);
            else {
                writeExplainMongos(result);
            }
        }
        else {
            // the array in which the aggregation results reside
            // cant use subArrayStart() due to error handling
            BSONArrayBuilder resultArray;
            DocumentSource* finalSource = sources.back().get();
            for (bool hasDoc = !finalSource->eof(); hasDoc; hasDoc = finalSource->advance()) {
                Document pDocument(finalSource->getCurrent());

                /* add the document to the result set */
                BSONObjBuilder documentBuilder (resultArray.subobjStart());
                pDocument->toBson(&documentBuilder);
                documentBuilder.doneFast();
                // object will be too large, assert. the extra 1KB is for headers
                uassert(16389,
                        str::stream() << "aggregation result exceeds maximum document size ("
                                      << BSONObjMaxUserSize / (1024 * 1024) << "MB)",
                        resultArray.len() < BSONObjMaxUserSize - 1024);
            }

            resultArray.done();
            result.appendArray("result", resultArray.arr());
        }
    }
开发者ID:calexandre,项目名称:mongo,代码行数:37,代码来源:pipeline.cpp

示例7: replHandshake

    bool SyncSourceFeedback::replHandshake() {
        // handshake for us
        BSONObjBuilder cmd;
        cmd.append("replSetUpdatePosition", 1);
        BSONObjBuilder sub (cmd.subobjStart("handshake"));
        sub.appendAs(_me["_id"], "handshake");
        sub.append("member", theReplSet->selfId());
        sub.append("config", theReplSet->myConfig().asBson());
        sub.doneFast();

        LOG(1) << "detecting upstream updater";
        BSONObj res;
        try {
            if (!_connection->runCommand("admin", cmd.obj(), res)) {
                if (res["errmsg"].str().find("no such cmd") != std::string::npos) {
                    LOG(1) << "upstream updater is not supported by the member from which we"
                              " are syncing, using oplogreader-based updating instead";
                    _supportsUpdater = false;
                }
                resetConnection();
                return false;
            }
            else {
                LOG(1) << "upstream updater is supported";
                _supportsUpdater = true;
            }
        }
        catch (const DBException& e) {
            log() << "SyncSourceFeedback error sending handshake: " << e.what() << endl;
            resetConnection();
            return false;
        }

        // handshakes for those connected to us
        {
            for (OIDMemberMap::iterator itr = _members.begin();
                 itr != _members.end(); ++itr) {
                BSONObjBuilder slaveCmd;
                slaveCmd.append("replSetUpdatePosition", 1);
                // outer handshake indicates this is a handshake command
                // inner is needed as part of the structure to be passed to gotHandshake
                BSONObjBuilder slaveSub (slaveCmd.subobjStart("handshake"));
                slaveSub.append("handshake", itr->first);
                slaveSub.append("member", itr->second->id());
                slaveSub.append("config", itr->second->config().asBson());
                slaveSub.doneFast();
                BSONObj slaveRes;
                try {
                    if (!_connection->runCommand("admin", slaveCmd.obj(), slaveRes)) {
                        resetConnection();
                        return false;
                    }
                }
                catch (const DBException& e) {
                    log() << "SyncSourceFeedback error sending chained handshakes: "
                          << e.what() << endl;
                    resetConnection();
                    return false;
                }
            }
        }
        return true;
    }
开发者ID:AshishThakur,项目名称:mongo,代码行数:63,代码来源:sync_source_feedback.cpp

示例8: replHandshake

    bool SyncSourceFeedback::replHandshake() {
        // handshake for us
        BSONObjBuilder cmd;
        cmd.append("replSetUpdatePosition", 1);
        BSONObjBuilder sub (cmd.subobjStart("handshake"));
        sub.appendAs(_me["_id"], "handshake");
        sub.append("member", theReplSet->selfId());
        sub.append("config", theReplSet->myConfig().asBson());
        sub.doneFast();

        LOG(1) << "detecting upstream updater";
        BSONObj res;
        try {
            if (!_connection->runCommand("admin", cmd.obj(), res)) {
                if (res["errmsg"].str().find("no such cmd") != std::string::npos) {
                    LOG(1) << "upstream updater is not supported by the member from which we"
                              " are syncing, using oplogreader-based updating instead";
                    _supportsUpdater = false;
                }
                resetConnection();
                return false;
            }
            else {
                LOG(1) << "upstream updater is supported";
                _supportsUpdater = true;
            }
        }
        catch (const DBException& e) {
            log() << "SyncSourceFeedback error sending handshake: " << e.what() << endl;
            resetConnection();
            return false;
        }

        // handshakes for those connected to us
        {
            OIDMemberMap::iterator itr = _members.begin();
            while (itr != _members.end()) {
                BSONObjBuilder slaveCmd;
                slaveCmd.append("replSetUpdatePosition", 1);
                // outer handshake indicates this is a handshake command
                // inner is needed as part of the structure to be passed to gotHandshake
                BSONObjBuilder slaveSub (slaveCmd.subobjStart("handshake"));
                slaveSub.append("handshake", itr->first);
                slaveSub.append("member", itr->second->id());
                slaveSub.append("config", itr->second->config().asBson());
                slaveSub.doneFast();
                BSONObj slaveRes;
                try {
                    if (!_connection->runCommand("admin", slaveCmd.obj(), slaveRes)) {
                        if (slaveRes["errmsg"].str().find("node could not be found ")
                                    != std::string::npos) {
                            if (!theReplSet->getMutableMember(itr->second->id())) {
                                log() << "sync source does not have member " << itr->second->id()
                                      << " in its config and neither do we, removing member from"
                                         " tracking";
                                OIDMemberMap::iterator removeItr = itr;
                                ++itr;
                                _slaveMap.erase(removeItr->first);
                                _members.erase(removeItr);
                                continue;
                            }
                            // here the node exists in our config, so do not stop tracking it
                            // and continue with the handshaking process
                        }
                        else {
                            resetConnection();
                            return false;
                        }
                    }
                }
                catch (const DBException& e) {
                    log() << "SyncSourceFeedback error sending chained handshakes: "
                          << e.what() << endl;
                    resetConnection();
                    return false;
                }
                ++itr;
            }
        }
        return true;
    }
开发者ID:joegen,项目名称:sipx-externals,代码行数:81,代码来源:sync_source_feedback.cpp


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