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


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

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


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

示例1: parseRolePossessionManipulationCommands

    Status parseRolePossessionManipulationCommands(const BSONObj& cmdObj,
                                                   const StringData& cmdName,
                                                   const std::string& dbname,
                                                   std::string* parsedName,
                                                   vector<RoleName>* parsedRoleNames,
                                                   BSONObj* parsedWriteConcern) {
        unordered_set<std::string> validFieldNames;
        validFieldNames.insert(cmdName.toString());
        validFieldNames.insert("roles");
        validFieldNames.insert("writeConcern");

        Status status = _checkNoExtraFields(cmdObj, cmdName, validFieldNames);
        if (!status.isOK()) {
            return status;
        }

        status = _extractWriteConcern(cmdObj, parsedWriteConcern);
        if (!status.isOK()) {
            return status;
        }

        status = bsonExtractStringField(cmdObj, cmdName, parsedName);
        if (!status.isOK()) {
            return status;
        }

        BSONElement rolesElement;
        status = bsonExtractTypedField(cmdObj, "roles", Array, &rolesElement);
        if (!status.isOK()) {
            return status;
        }

        status = parseRoleNamesFromBSONArray(BSONArray(rolesElement.Obj()),
                                             dbname,
                                             parsedRoleNames);
        if (!status.isOK()) {
            return status;
        }

        if (!parsedRoleNames->size()) {
            return Status(ErrorCodes::BadValue,
                          mongoutils::str::stream() << cmdName << " command requires a non-empty "
                                  "\"roles\" array");
        }
        return Status::OK();
    }
开发者ID:kevleyski,项目名称:mongo,代码行数:46,代码来源:user_management_commands_parser.cpp

示例2: _mergeCommandResult

    void WriteResult::_mergeCommandResult(
        const std::vector<WriteOperation*>& ops,
        const BSONObj& result
    ) {
        int affected = _getIntOrDefault(result, "n");

        // Handle Write Batch
        switch (ops.front()->operationType()) {
            case dbWriteInsert:
                _nInserted += affected;
                break;

            case dbWriteDelete:
                _nRemoved += affected;
                break;

            case dbWriteUpdate:
                if (result.hasField("upserted")) {
                    int nUpserted = _createUpserts(result.getField("upserted"), ops);
                    _nUpserted += nUpserted;
                    _nMatched += (affected - nUpserted);
                } else {
                    _nMatched += affected;
                }

                _setModified(result);

                break;
        }

        // Handle Write Errors
        if (result.hasField("writeErrors")) {
            BSONElement writeErrors = result.getField("writeErrors");
            BSONObjIterator arrayIterator(writeErrors.Obj());
            BSONElement current;

            while (arrayIterator.more())
                _createWriteError(arrayIterator.next().Obj(), ops);
        }

        // Handle Write Concern Errors
        if (result.hasField("writeConcernError")) {
            BSONObj writeConcernError = result.getObjectField("writeConcernError");
            _createWriteConcernError(writeConcernError);
        }
    }
开发者ID:weakwater,项目名称:easy,代码行数:46,代码来源:write_result.cpp

示例3: move

StatusWith<std::vector<BSONObj>> AggregationRequest::parsePipelineFromBSON(
    BSONElement pipelineElem) {
    std::vector<BSONObj> pipeline;
    if (pipelineElem.eoo() || pipelineElem.type() != BSONType::Array) {
        return {ErrorCodes::TypeMismatch, "'pipeline' option must be specified as an array"};
    }

    for (auto elem : pipelineElem.Obj()) {
        if (elem.type() != BSONType::Object) {
            return {ErrorCodes::TypeMismatch,
                    "Each element of the 'pipeline' array must be an object"};
        }
        pipeline.push_back(elem.embeddedObject().getOwned());
    }

    return std::move(pipeline);
}
开发者ID:louiswilliams,项目名称:mongo,代码行数:17,代码来源:aggregation_request.cpp

示例4: _parseTreeList

    Status ExpressionParser::_parseTreeList( const BSONObj& arr, ListOfExpression* out ) {
        BSONObjIterator i( arr );
        while ( i.more() ) {
            BSONElement e = i.next();

            if ( e.type() != Object )
                return Status( ErrorCodes::BadValue,
                               "$or/$and/$nor entries need to be full objects" );

            StatusWithExpression sub = parse( e.Obj() );
            if ( !sub.isOK() )
                return sub.getStatus();

            out->add( sub.getValue() );
        }
        return Status::OK();
    }
开发者ID:avish,项目名称:mongo,代码行数:17,代码来源:expression_parser_tree.cpp

示例5: if

StatusWith<ReadPreferenceSetting> ReadPreferenceSetting::fromBSON(const BSONObj& readPrefObj) {
    std::string modeStr;
    auto modeExtractStatus = bsonExtractStringField(readPrefObj, kModeFieldName, &modeStr);
    if (!modeExtractStatus.isOK()) {
        return modeExtractStatus;
    }

    ReadPreference mode;
    auto swReadPrefMode = parseReadPreferenceMode(modeStr);
    if (!swReadPrefMode.isOK()) {
        return swReadPrefMode.getStatus();
    }
    mode = std::move(swReadPrefMode.getValue());

    TagSet tags;
    BSONElement tagsElem;
    auto tagExtractStatus =
        bsonExtractTypedField(readPrefObj, kTagsFieldName, mongo::Array, &tagsElem);
    if (tagExtractStatus.isOK()) {
        tags = TagSet{BSONArray(tagsElem.Obj().getOwned())};

        // In accordance with the read preference spec, passing the default wildcard tagset
        // '[{}]' is the same as not passing a TagSet at all. Furthermore, passing an empty
        // TagSet with a non-primary ReadPreference is equivalent to passing the wildcard
        // ReadPreference.
        if (tags == TagSet() || tags == TagSet::primaryOnly()) {
            tags = defaultTagSetForMode(mode);
        }

        // If we are using a user supplied TagSet, check that it is compatible with
        // the readPreference mode.
        else if (ReadPreference::PrimaryOnly == mode && (tags != TagSet::primaryOnly())) {
            return Status(ErrorCodes::BadValue,
                          "Only empty tags are allowed with primary read preference");
        }
    }

    else if (ErrorCodes::NoSuchKey == tagExtractStatus) {
        tags = defaultTagSetForMode(mode);
    } else {
        return tagExtractStatus;
    }

    return ReadPreferenceSetting(mode, tags);
}
开发者ID:alabid,项目名称:mongo,代码行数:45,代码来源:read_preference.cpp

示例6: parseDeleteCommand

DeleteOp parseDeleteCommand(StringData dbName, const BSONObj& cmd) {
    BSONElement deletes;
    DeleteOp op;
    parseWriteCommand(dbName, cmd, "deletes", &deletes, &op);
    checkType(Array, deletes);
    for (auto doc : deletes.Obj()) {
        checkTypeInArray(Object, doc, deletes);
        op.deletes.emplace_back();
        auto& del = op.deletes.back();  // delete is a reserved word.
        bool haveQ = false;
        bool haveLimit = false;
        for (auto field : doc.Obj()) {
            const StringData fieldName = field.fieldNameStringData();
            if (fieldName == "q") {
                haveQ = true;
                checkType(Object, field);
                del.query = field.Obj();
            } else if (fieldName == "limit") {
                haveLimit = true;
                uassert(ErrorCodes::TypeMismatch,
                        str::stream()
                            << "The limit field in delete objects must be a number. Got a "
                            << typeName(field.type()),
                        field.isNumber());

                // Using a double to avoid throwing away illegal fractional portion. Don't want to
                // accept 0.5 here.
                const double limit = field.numberDouble();
                uassert(ErrorCodes::FailedToParse,
                        str::stream() << "The limit field in delete objects must be 0 or 1. Got "
                                      << limit,
                        limit == 0 || limit == 1);
                del.multi = (limit == 0);
            } else {
                uasserted(ErrorCodes::FailedToParse,
                          str::stream() << "Unrecognized field in delete operation: " << fieldName);
            }
        }
        uassert(ErrorCodes::FailedToParse, "The 'q' field is required for all deletes", haveQ);
        uassert(
            ErrorCodes::FailedToParse, "The 'limit' field is required for all deletes", haveLimit);
    }
    checkOpCountForCommand(op.deletes.size());
    return op;
}
开发者ID:GodotGo,项目名称:mongo,代码行数:45,代码来源:write_ops_parsers.cpp

示例7: getHaystackKeys

// static
void ExpressionKeysPrivate::getHaystackKeys(const BSONObj& obj,
        const std::string& geoField,
        const std::vector<std::string>& otherFields,
        double bucketSize,
        BSONObjSet* keys) {

    BSONElement loc = obj.getFieldDotted(geoField);

    if (loc.eoo()) {
        return;
    }

    uassert(16775, "latlng not an array", loc.isABSONObj());
    string root;
    {
        BSONObjIterator i(loc.Obj());
        BSONElement x = i.next();
        BSONElement y = i.next();
        root = makeHaystackString(hashHaystackElement(x, bucketSize),
                                  hashHaystackElement(y, bucketSize));
    }

    verify(otherFields.size() == 1);

    BSONElementSet all;

    // This is getFieldsDotted (plural not singular) since the object we're indexing
    // may be an array.
    obj.getFieldsDotted(otherFields[0], all);

    if (all.size() == 0) {
        // We're indexing a document that doesn't have the secondary non-geo field present.
        // XXX: do we want to add this even if all.size() > 0?  result:empty search terms
        // match everything instead of only things w/empty search terms)
        addKey(root, BSONElement(), keys);
    } else {
        // Ex:If our secondary field is type: "foo" or type: {a:"foo", b:"bar"},
        // all.size()==1.  We can query on the complete field.
        // Ex: If our secondary field is type: ["A", "B"] all.size()==2 and all has values
        // "A" and "B".  The query looks for any of the fields in the array.
        for (BSONElementSet::iterator i = all.begin(); i != all.end(); ++i) {
            addKey(root, *i, keys);
        }
    }
}
开发者ID:husttom,项目名称:mongo,代码行数:46,代码来源:expression_keys_private.cpp

示例8: parseAndValidateRolePrivilegeManipulationCommands

    Status parseAndValidateRolePrivilegeManipulationCommands(const BSONObj& cmdObj,
                                                             const StringData& cmdName,
                                                             const std::string& dbname,
                                                             RoleName* parsedRoleName,
                                                             PrivilegeVector* parsedPrivileges,
                                                             BSONObj* parsedWriteConcern) {
        unordered_set<std::string> validFieldNames;
        validFieldNames.insert(cmdName.toString());
        validFieldNames.insert("privileges");
        validFieldNames.insert("writeConcern");

        Status status = _checkNoExtraFields(cmdObj, cmdName, validFieldNames);
        if (!status.isOK()) {
            return status;
        }

        status = _extractWriteConcern(cmdObj, parsedWriteConcern);
        if (!status.isOK()) {
            return status;
        }

        BSONObjBuilder roleObjBuilder;

        // Parse role name
        std::string roleName;
        status = bsonExtractStringField(cmdObj, cmdName, &roleName);
        if (!status.isOK()) {
            return status;
        }
        *parsedRoleName = RoleName(roleName, dbname);

        // Parse privileges
        BSONElement privilegesElement;
        status = bsonExtractTypedField(cmdObj, "privileges", Array, &privilegesElement);
        if (!status.isOK()) {
            return status;
        }
        status = _parseAndValidatePrivilegeArray(BSONArray(privilegesElement.Obj()),
                                                 parsedPrivileges);
        if (!status.isOK()) {
            return status;
        }

        return Status::OK();
    }
开发者ID:Hokutosei,项目名称:mongo,代码行数:45,代码来源:user_management_commands_parser.cpp

示例9: parseQuery

    Status GeoExpression::parseQuery(const BSONObj &obj) {
        BSONObjIterator outerIt(obj);
        // "within" / "geoWithin" / "geoIntersects"
        BSONElement queryElt = outerIt.next();
        if (outerIt.more()) {
            return Status(ErrorCodes::BadValue,
                          str::stream() << "can't parse extra field: " << outerIt.next());
        }

        BSONObj::MatchType matchType = static_cast<BSONObj::MatchType>(queryElt.getGtLtOp());
        if (BSONObj::opGEO_INTERSECTS == matchType) {
            predicate = GeoExpression::INTERSECT;
        } else if (BSONObj::opWITHIN == matchType) {
            predicate = GeoExpression::WITHIN;
        } else {
            // eoo() or unknown query predicate.
            return Status(ErrorCodes::BadValue,
                          str::stream() << "invalid geo query predicate: " << obj);
        }

        // Parse geometry after predicates.
        if (Object != queryElt.type()) return Status(ErrorCodes::BadValue, "geometry must be an object");
        BSONObj geoObj = queryElt.Obj();

        BSONObjIterator geoIt(geoObj);

        while (geoIt.more()) {
            BSONElement elt = geoIt.next();
            if (str::equals(elt.fieldName(), "$uniqueDocs")) {
                // Deprecated "$uniqueDocs" field
                warning() << "deprecated $uniqueDocs option: " << obj.toString() << endl;
            } else {
                // The element must be a geo specifier. "$box", "$center", "$geometry", etc.
                geoContainer.reset(new GeometryContainer());
                Status status = geoContainer->parseFromQuery(elt);
                if (!status.isOK()) return status;
            }
        }

        if (geoContainer == NULL) {
            return Status(ErrorCodes::BadValue, "geo query doesn't have any geometry");
        }

        return Status::OK();
    }
开发者ID:Rockyit,项目名称:mongo,代码行数:45,代码来源:expression_geo.cpp

示例10: bsonExtractOpTimeField

Status bsonExtractOpTimeField(const BSONObj& object, StringData fieldName, repl::OpTime* out) {
    BSONElement element;
    Status status = bsonExtractTypedField(object, fieldName, Object, &element);
    if (!status.isOK())
        return status;

    BSONObj opTimeObj = element.Obj();
    Timestamp ts;
    status = bsonExtractTimestampField(opTimeObj, kTimestampFieldName, &ts);
    if (!status.isOK())
        return status;
    long long term;
    status = bsonExtractIntegerField(opTimeObj, kTermFieldName, &term);
    if (!status.isOK())
        return status;
    *out = repl::OpTime(ts, term);
    return Status::OK();
}
开发者ID:mongodbinc-interns,项目名称:mongo,代码行数:18,代码来源:bson_extract.cpp

示例11: addEquality

Status InMatchExpression::addEquality(const BSONElement& elt) {
    if (elt.type() == BSONType::RegEx) {
        return Status(ErrorCodes::BadValue, "InMatchExpression equality cannot be a regex");
    }
    if (elt.type() == BSONType::Undefined) {
        return Status(ErrorCodes::BadValue, "InMatchExpression equality cannot be undefined");
    }

    if (elt.type() == BSONType::jstNULL) {
        _hasNull = true;
    }
    if (elt.type() == BSONType::Array && elt.Obj().isEmpty()) {
        _hasEmptyArray = true;
    }
    _equalitySet.insert(elt);
    _originalEqualityVector.push_back(elt);
    return Status::OK();
}
开发者ID:mikety,项目名称:mongo,代码行数:18,代码来源:expression_leaf.cpp

示例12: _matchesElementExpandArray

bool LeafMatchExpression::_matchesElementExpandArray( const BSONElement& e ) const {
    if ( e.eoo() )
        return false;

    if ( matchesSingleElement( e ) )
        return true;

    if ( e.type() == Array ) {
        BSONObjIterator i( e.Obj() );
        while ( i.more() ) {
            BSONElement sub = i.next();
            if ( matchesSingleElement( sub ) )
                return true;
        }
    }

    return false;
}
开发者ID:bieli,项目名称:mongo,代码行数:18,代码来源:expression_leaf.cpp

示例13: initializeShardVersion

void OperationShardingState::initializeShardVersion(NamespaceString nss,
                                                    const BSONElement& shardVersionElt) {
    invariant(!hasShardVersion());

    if (shardVersionElt.eoo() || shardVersionElt.type() != BSONType::Array) {
        return;
    }

    const BSONArray versionArr(shardVersionElt.Obj());
    bool hasVersion = false;
    ChunkVersion newVersion = ChunkVersion::fromBSON(versionArr, &hasVersion);

    if (!hasVersion) {
        return;
    }

    setShardVersion(std::move(nss), std::move(newVersion));
}
开发者ID:miracleCF,项目名称:mongo,代码行数:18,代码来源:operation_sharding_state.cpp

示例14: addEquality

Status ArrayFilterEntries::addEquality(const BSONElement& e) {
    if (e.type() == RegEx)
        return Status(ErrorCodes::BadValue, "ArrayFilterEntries equality cannot be a regex");

    if (e.type() == Undefined) {
        return Status(ErrorCodes::BadValue, "ArrayFilterEntries equality cannot be undefined");
    }

    if (e.type() == jstNULL) {
        _hasNull = true;
    }

    if (e.type() == Array && e.Obj().isEmpty())
        _hasEmptyArray = true;

    _equalities.insert(e);
    return Status::OK();
}
开发者ID:RaeCai,项目名称:mongo,代码行数:18,代码来源:expression_leaf.cpp

示例15: _isExpressionDocument

    bool MatchExpressionParser::_isExpressionDocument( const BSONElement& e ) {
        if ( e.type() != Object )
            return false;

        BSONObj o = e.Obj();
        if ( o.isEmpty() )
            return false;

        const char* name = o.firstElement().fieldName();
        if ( name[0] != '$' )
            return false;

        if ( _isDBRefDocument( o ) ) {
            return false;
        }

        return true;
    }
开发者ID:senyangwu,项目名称:mongo,代码行数:18,代码来源:expression_parser.cpp


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