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


C++ Query::getFilter方法代码示例

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


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

示例1: calculateConfigDiff

int ConfigDiffTracker<ValType, ShardType>::calculateConfigDiff(CatalogManager* catalogManager) {
    _assertAttached();

    // Get the diff query required
    Query diffQuery = configDiffQuery();

    try {
        std::vector<ChunkType> chunks;
        uassertStatusOK(catalogManager->getChunks(
                            diffQuery.getFilter(), diffQuery.getSort(), boost::none, &chunks));

        return calculateConfigDiff(chunks);
    } catch (DBException& e) {
        // Should only happen on connection errors
        e.addContext(str::stream() << "could not calculate config difference for ns " << _ns);
        throw;
    }
}
开发者ID:wenhailong,项目名称:mongo,代码行数:18,代码来源:chunk_diff.cpp

示例2: canHandleQuery

    bool SCCFastQueryHandler::canHandleQuery(const string& ns, Query query) {

        if (!internalSCCAllowFastestAuthConfigReads &&
            !internalSCCAllowFastestMetadataConfigReads) {
            return false;
        }

        //
        // More operations can be added here
        //
        // NOTE: Not all operations actually pass through the SCC _queryOnActive path - notable
        // exceptions include anything related to direct query ops and direct operations for
        // connection maintenance.
        //

        NamespaceString nss(ns);
        if (nss.isCommand()) {
            BSONObj cmdObj = query.getFilter();
            string cmdName = cmdObj.firstElement().fieldName();
            if (cmdName == "usersInfo")
                return true;
        }
        else if (nss.coll() == "system.users") {
            return true;
        }

        //
        // Allow fastest config reads for all collections except for those involved in locks and
        // cluster versioning.
        //

        if (!internalSCCAllowFastestMetadataConfigReads)
            return false;

        if (nss.db() != "config")
            return false;

        if (nss.coll() != "version" && nss.coll() != "locks" && nss.coll() != "lockpings") {
            return true;
        }

        return false;
    }
开发者ID:7segments,项目名称:mongo-1,代码行数:43,代码来源:scc_fast_query_handler.cpp

示例3: run

        virtual bool run(const string& dbname, BSONObj& cmdObj, int x, string& errmsg, BSONObjBuilder& result, bool y) {
            static DBDirectClient db;

            if ( cmdObj["sort"].eoo() )
                return runNoDirectClient( dbname , cmdObj , x, errmsg , result, y );

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

            BSONObj origQuery = cmdObj.getObjectField("query"); // defaults to {}
            Query q (origQuery);
            BSONElement sort = cmdObj["sort"];
            if (!sort.eoo())
                q.sort(sort.embeddedObjectUserCheck());

            bool upsert = cmdObj["upsert"].trueValue();

            BSONObj fieldsHolder (cmdObj.getObjectField("fields"));
            const BSONObj* fields = (fieldsHolder.isEmpty() ? NULL : &fieldsHolder);

            Projection projection;
            if (fields) {
                projection.init(fieldsHolder);
                if (!projection.includeID())
                    fields = NULL; // do projection in post-processing
            }

            BSONObj out = db.findOne(ns, q, fields);
            if (out.isEmpty()) {
                if (!upsert) {
                    result.appendNull("value");
                    return true;
                }

                BSONElement update = cmdObj["update"];
                uassert(13329, "upsert mode requires update field", !update.eoo());
                uassert(13330, "upsert mode requires query field", !origQuery.isEmpty());
                db.update(ns, origQuery, update.embeddedObjectUserCheck(), true);

                BSONObj gle = db.getLastErrorDetailed(dbname);
                result.append("lastErrorObject", gle);
                if (gle["err"].type() == String) {
                    errmsg = gle["err"].String();
                    return false;
                }

                if (cmdObj["new"].trueValue()) {
                    BSONElement _id = gle["upserted"];
                    if (_id.eoo())
                        _id = origQuery["_id"];

                    out = db.findOne(ns, QUERY("_id" << _id), fields);
                }

            }
            else {

                if (cmdObj["remove"].trueValue()) {
                    uassert(12515, "can't remove and update", cmdObj["update"].eoo());
                    db.remove(ns, QUERY("_id" << out["_id"]), 1);

                    BSONObj gle = db.getLastErrorDetailed(dbname);
                    result.append("lastErrorObject", gle);
                    if (gle["err"].type() == String) {
                        errmsg = gle["err"].String();
                        return false;
                    }

                }
                else {   // update

                    BSONElement queryId = origQuery["_id"];
                    if (queryId.eoo() || getGtLtOp(queryId) != BSONObj::Equality) {
                        // need to include original query for $ positional operator

                        BSONObjBuilder b;
                        b.append(out["_id"]);
                        BSONObjIterator it(origQuery);
                        while (it.more()) {
                            BSONElement e = it.next();
                            if (strcmp(e.fieldName(), "_id"))
                                b.append(e);
                        }
                        q = Query(b.obj());
                    }

                    if (q.isComplex()) // update doesn't work with complex queries
                        q = Query(q.getFilter().getOwned());

                    BSONElement update = cmdObj["update"];
                    uassert(12516, "must specify remove or update", !update.eoo());
                    db.update(ns, q, update.embeddedObjectUserCheck());

                    BSONObj gle = db.getLastErrorDetailed(dbname);
                    result.append("lastErrorObject", gle);
                    if (gle["err"].type() == String) {
                        errmsg = gle["err"].String();
                        return false;
                    }

                    if (cmdObj["new"].trueValue())
//.........这里部分代码省略.........
开发者ID:10genReviews,项目名称:mongo,代码行数:101,代码来源:find_and_modify.cpp


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