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


C++ BSONObj::hasField方法代码示例

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


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

示例1: _run

        bool _run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
            if( cmdObj["replSetReconfig"].type() != Object ) {
                errmsg = "no configuration specified";
                return false;
            }

            ReplicationCoordinator::ReplSetReconfigArgs parsedArgs;
            parsedArgs.newConfigObj =  cmdObj["replSetReconfig"].Obj();
            parsedArgs.force = cmdObj.hasField("force") && cmdObj["force"].trueValue();
            Status status = getGlobalReplicationCoordinator()->processReplSetReconfig(txn,
                                                                                      parsedArgs,
                                                                                      &result);
            return appendCommandStatus(result, status);
        }
开发者ID:DesignByOnyx,项目名称:mongo,代码行数:14,代码来源:replset_commands.cpp

示例2: checkAuthForApplyOpsCommand

Status checkAuthForApplyOpsCommand(OperationContext* txn,
                                   const std::string& dbname,
                                   const BSONObj& cmdObj) {
    AuthorizationSession* authSession = AuthorizationSession::get(txn->getClient());

    ApplyOpsValidity validity = validateApplyOpsCommand(cmdObj);
    if (validity == ApplyOpsValidity::kNeedsSuperuser) {
        std::vector<Privilege> universalPrivileges;
        RoleGraph::generateUniversalPrivileges(&universalPrivileges);
        if (!authSession->isAuthorizedForPrivileges(universalPrivileges)) {
            return Status(ErrorCodes::Unauthorized, "Unauthorized");
        }
        return Status::OK();
    }
    fassert(40314, validity == ApplyOpsValidity::kOk);

    boost::optional<DisableDocumentValidation> maybeDisableValidation;
    if (shouldBypassDocumentValidationForCommand(cmdObj))
        maybeDisableValidation.emplace(txn);


    const bool alwaysUpsert =
        cmdObj.hasField("alwaysUpsert") ? cmdObj["alwaysUpsert"].trueValue() : true;

    checkBSONType(BSONType::Array, cmdObj.firstElement());
    for (const BSONElement& e : cmdObj.firstElement().Array()) {
        checkBSONType(BSONType::Object, e);
        Status status = checkOperationAuthorization(txn, dbname, e.Obj(), alwaysUpsert);
        if (!status.isOK()) {
            return status;
        }
    }

    BSONElement preconditions = cmdObj["preCondition"];
    if (!preconditions.eoo()) {
        for (const BSONElement& precondition : preconditions.Array()) {
            checkBSONType(BSONType::Object, precondition);
            BSONElement nsElem = precondition.Obj()["ns"];
            checkBSONType(BSONType::String, nsElem);
            NamespaceString nss(nsElem.checkAndGetStringData());

            if (!authSession->isAuthorizedForActionsOnResource(
                    ResourcePattern::forExactNamespace(nss), ActionType::find)) {
                return Status(ErrorCodes::Unauthorized, "Unauthorized to check precondition");
            }
        }
    }

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

示例3: Status

StatusWith<std::vector<BSONElement>> DatabasesCloner::_parseListDatabasesResponse(
    BSONObj dbResponse) {
    if (!dbResponse.hasField("databases")) {
        return Status(ErrorCodes::BadValue,
                      "The 'listDatabases' response does not contain a 'databases' field.");
    }
    BSONElement response = dbResponse["databases"];
    try {
        return response.Array();
    } catch (const AssertionException&) {
        return Status(ErrorCodes::BadValue,
                      "The 'listDatabases' response is unable to be transformed into an array.");
    }
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:14,代码来源:databases_cloner.cpp

示例4: run

 bool run(
     const string& db,
     BSONObj& cmdObj,
     int options, string& errmsg,
     BSONObjBuilder& result,
     bool fromRepl = false )
 {
     if (cmdObj.hasField("reset")) {
         ReplSetConfig::OPLOG_VERSION = ReplSetConfig::OPLOG_VERSION_CURRENT;
     }
     else {
         ReplSetConfig::OPLOG_VERSION = ReplSetConfig::OPLOG_VERSION_TEST;
     }
     return true;
 }
开发者ID:xbsura,项目名称:tokumx,代码行数:15,代码来源:testhooks.cpp

示例5: Status

StatusWith<std::vector<BSONElement>> CollectionCloner::_parseParallelCollectionScanResponse(
    BSONObj resp) {
    if (!resp.hasField("cursors")) {
        return Status(ErrorCodes::CursorNotFound,
                      "The 'parallelCollectionScan' response does not contain a 'cursors' field.");
    }
    BSONElement response = resp["cursors"];
    if (response.type() == BSONType::Array) {
        return response.Array();
    } else {
        return Status(
            ErrorCodes::FailedToParse,
            "The 'parallelCollectionScan' response is unable to be transformed into an array.");
    }
}
开发者ID:i80and,项目名称:mongo,代码行数:15,代码来源:collection_cloner.cpp

示例6: run

        virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
            if( !check(errmsg, result) )
                return false;

            bool force = cmdObj.hasField("force") && cmdObj["force"].trueValue();
            int secs = (int) cmdObj.firstElement().numberInt();
            if( secs == 0 )
                secs = 60;

            Status status = getGlobalReplicationCoordinator()->stepDown(
                    force,
                    ReplicationCoordinator::Milliseconds(0),
                    ReplicationCoordinator::Milliseconds(secs * 1000));
            return appendCommandStatus(result, status);
        }
开发者ID:ZhangHongJi,项目名称:mongo,代码行数:15,代码来源:replset_commands.cpp

示例7: GetIntFieldValue

int CMongodbModel::GetIntFieldValue(BSONObj boRecord, string strFieldName, 
									int iExceptionValue)
{
	int iValue = iExceptionValue;
	if (boRecord.hasField(strFieldName))
	{		
		try 
		{
			iValue = boRecord.getIntField(strFieldName.c_str());
		}
		catch(exception& ex) {}
	}

	return iValue;
}
开发者ID:fr34k8,项目名称:CMDBv2,代码行数:15,代码来源:MongodbModel.cpp

示例8: if

    Status V1UserDocumentParser::initializeUserCredentialsFromUserDocument(
            User* user, const BSONObj& privDoc) const {
        User::CredentialData credentials;
        if (privDoc.hasField(AuthorizationManager::PASSWORD_FIELD_NAME)) {
            credentials.password = privDoc[AuthorizationManager::PASSWORD_FIELD_NAME].String();
            credentials.isExternal = false;
        }
        else if (privDoc.hasField(AuthorizationManager::V1_USER_SOURCE_FIELD_NAME)) {
            std::string userSource = privDoc[AuthorizationManager::V1_USER_SOURCE_FIELD_NAME].String();
            if (userSource != "$external") {
                return Status(ErrorCodes::UnsupportedFormat,
                              "Cannot extract credentials from user documents without a password "
                              "and with userSource != \"$external\"");
            } else {
                credentials.isExternal = true;
            }
        } else {
            return Status(ErrorCodes::UnsupportedFormat,
                          "Invalid user document: must have one of \"pwd\" and \"userSource\"");
        }

        user->setCredentials(credentials);
        return Status::OK();
    }
开发者ID:chenziya,项目名称:mongo,代码行数:24,代码来源:user_document_parser.cpp

示例9: updateOne

Status AuthzManagerExternalStateMock::updateOne(OperationContext* txn,
                                                const NamespaceString& collectionName,
                                                const BSONObj& query,
                                                const BSONObj& updatePattern,
                                                bool upsert,
                                                const BSONObj& writeConcern) {
    namespace mmb = mutablebson;
    UpdateDriver::Options updateOptions;
    UpdateDriver driver(updateOptions);
    Status status = driver.parse(updatePattern);
    if (!status.isOK())
        return status;

    BSONObjCollection::iterator iter;
    status = _findOneIter(collectionName, query, &iter);
    mmb::Document document;
    if (status.isOK()) {
        document.reset(*iter, mmb::Document::kInPlaceDisabled);
        BSONObj logObj;
        status = driver.update(StringData(), &document, &logObj);
        if (!status.isOK())
            return status;
        BSONObj newObj = document.getObject().copy();
        *iter = newObj;
        BSONObj idQuery = driver.makeOplogEntryQuery(newObj, false);

        if (_authzManager) {
            _authzManager->logOp(txn, "u", collectionName.ns().c_str(), logObj, &idQuery);
        }

        return Status::OK();
    } else if (status == ErrorCodes::NoMatchingDocument && upsert) {
        if (query.hasField("_id")) {
            document.root().appendElement(query["_id"]);
        }
        status = driver.populateDocumentWithQueryFields(query, NULL, document);
        if (!status.isOK()) {
            return status;
        }
        status = driver.update(StringData(), &document);
        if (!status.isOK()) {
            return status;
        }
        return insert(txn, collectionName, document.getObject(), writeConcern);
    } else {
        return status;
    }
}
开发者ID:hAhmadz,项目名称:mongo,代码行数:48,代码来源:authz_manager_external_state_mock.cpp

示例10: buildPrivilegeSet

 Status AuthorizationManager::buildPrivilegeSet(const std::string& dbname,
                                                const PrincipalName& principal,
                                                const BSONObj& privilegeDocument,
                                                PrivilegeSet* result) {
     if (!privilegeDocument.hasField(ROLES_FIELD_NAME)) {
         // Old-style (v2.2 and prior) privilege document
         return _buildPrivilegeSetFromOldStylePrivilegeDocument(dbname,
                                                                principal,
                                                                privilegeDocument,
                                                                result);
     }
     else {
         return _buildPrivilegeSetFromExtendedPrivilegeDocument(
                 dbname, principal, privilegeDocument, result);
     }
 }
开发者ID:jxn0715,项目名称:mongo,代码行数:16,代码来源:authorization_manager.cpp

示例11: setCount

/* ****************************************************************************
*
* setCount -
*/
static void setCount(long long inc, const BSONObj& subOrig, BSONObjBuilder* b)
{
  if (subOrig.hasField(CSUB_COUNT))
  {
    long long count = getIntOrLongFieldAsLongF(subOrig, CSUB_COUNT);
    setCount(count + inc, b);
  }
  else
  {
    // In this case we only add if inc is different from 0
    if (inc > 0)
    {
      setCount(inc, b);
    }
  }
}
开发者ID:telefonicaid,项目名称:fiware-orion,代码行数:20,代码来源:mongoUpdateSubscription.cpp

示例12: init

    Status LiteParsedQuery::init(const string& ns, int ntoskip, int ntoreturn, int queryOptions,
                                 const BSONObj& queryObj, const BSONObj& proj,
                                 bool fromQueryMessage) {
        _ns = ns;
        _ntoskip = ntoskip;
        _ntoreturn = ntoreturn;
        _options = queryOptions;
        _proj = proj.getOwned();

        if (_ntoskip < 0) {
            return Status(ErrorCodes::BadValue, "bad skip value in query");
        }
        
        if (_ntoreturn < 0) {
            // _ntoreturn greater than zero is simply a hint on how many objects to send back per
            // "cursor batch".  A negative number indicates a hard limit.
            _wantMore = false;
            _ntoreturn = -_ntoreturn;
        }

        if (fromQueryMessage) {
            BSONElement queryField = queryObj["query"];
            if (!queryField.isABSONObj()) { queryField = queryObj["$query"]; }
            if (queryField.isABSONObj()) {
                _filter = queryField.embeddedObject().getOwned();
                Status status = initFullQuery(queryObj);
                if (!status.isOK()) { return status; }
            }
            else {
                // TODO: Does this ever happen?
                _filter = queryObj.getOwned();
            }
        }
        else {
            // This is the debugging code path.
            _filter = queryObj.getOwned();
        }

        _hasReadPref = queryObj.hasField("$readPreference");

        if (!isValidSortOrder(_sort)) {
            return Status(ErrorCodes::BadValue, "bad sort specification");
        }
        _sort = normalizeSortOrder(_sort);

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

示例13: createCollectionWithOptions

    void createCollectionWithOptions(BSONObj obj) {
        BSONObjIterator i(obj);

        // Rebuild obj as a command object for the "create" command.
        // - {create: <name>} comes first, where <name> is the new name for the collection
        // - elements with type Undefined get skipped over
        BSONObjBuilder bo;
        bo.append("create", _curcoll);
        while (i.more()) {
            BSONElement e = i.next();

            if (strcmp(e.fieldName(), "create") == 0) {
                continue;
            }

            if (e.type() == Undefined) {
                log() << _curns << ": skipping undefined field: " << e.fieldName() << endl;
                continue;
            }

            bo.append(e);
        }
        obj = bo.obj();

        BSONObj fields = BSON("options" << 1);
        scoped_ptr<DBClientCursor> cursor(conn().query(_curdb + ".system.namespaces", Query(BSON("name" << _curns)), 0, 0, &fields));

        bool createColl = true;
        if (cursor->more()) {
            createColl = false;
            BSONObj nsObj = cursor->next();
            if (!nsObj.hasField("options") || !optionsSame(obj, nsObj["options"].Obj())) {
                    log() << "WARNING: collection " << _curns << " exists with different options than are in the metadata.json file and not using --drop. Options in the metadata file will be ignored." << endl;
            }
        }

        if (!createColl) {
            return;
        }

        BSONObj info;
        if (!conn().runCommand(_curdb, obj, info)) {
            uasserted(15936, "Creating collection " + _curns + " failed. Errmsg: " + info["errmsg"].String());
        } else {
            log() << "\tCreated collection " << _curns << " with options: " << obj.jsonString() << endl;
        }
    }
开发者ID:xbsura,项目名称:tokumx,代码行数:47,代码来源:restore.cpp

示例14: setSubject

/* ****************************************************************************
*
* setSubject -
*/
static void setSubject(Subscription* s, const BSONObj& r)
{
  // Entities
  std::vector<BSONElement> ents = getField(r, CSUB_ENTITIES).Array();
  for (unsigned int ix = 0; ix < ents.size(); ++ix)
  {
    BSONObj ent           = ents[ix].embeddedObject();
    std::string id        = getStringField(ent, CSUB_ENTITY_ID);
    std::string type      = ent.hasField(CSUB_ENTITY_TYPE)? getStringField(ent, CSUB_ENTITY_TYPE) : "";
    std::string isPattern = getStringField(ent, CSUB_ENTITY_ISPATTERN);

    EntID en;
    if (isFalse(isPattern))
    {
      en.id = id;
    }
    else
    {
      en.idPattern = id;
    }
    en.type = type;

    s->subject.entities.push_back(en);
  }

  // Condition
  std::vector<BSONElement> conds = getField(r, CSUB_CONDITIONS).Array();
  for (unsigned int ix = 0; ix < conds.size(); ++ix)
  {
    BSONObj cond = conds[ix].embeddedObject();
    // The ONCHANGE check is needed, as a subscription could mix different conditions types in DB
    if (std::string(getStringField(cond, CSUB_CONDITIONS_TYPE)) == "ONCHANGE")
    {
      std::vector<BSONElement> condValues = getField(cond, CSUB_CONDITIONS_VALUE).Array();
      for (unsigned int jx = 0; jx < condValues.size(); ++jx)
      {
        std::string attr = condValues[jx].String();
        s->subject.condition.attributes.push_back(attr);
      }
    }
  }

  // Note that current DB model is based on NGSIv1 and doesn't consider expressions. Thus
  // subject.condition.expression cannot be filled. The implemetion will be enhanced once
  // the DB model gets defined
  // TBD
}
开发者ID:fiwareulpgcmirror,项目名称:fiware-orion,代码行数:51,代码来源:mongoGetSubscriptions.cpp

示例15: setDescription

/* ****************************************************************************
*
* setDescription -
*/
static void setDescription(const SubscriptionUpdate& subUp, const BSONObj& subOrig, BSONObjBuilder* b)
{
  if (subUp.descriptionProvided)
  {
    setDescription(subUp, b);
  }
  else
  {
    if (subOrig.hasField(CSUB_DESCRIPTION))
    {
      std::string description = getStringFieldF(subOrig, CSUB_DESCRIPTION);

      b->append(CSUB_DESCRIPTION, description);
      LM_T(LmtMongo, ("Subscription description: %s", description.c_str()));
    }
  }
}
开发者ID:telefonicaid,项目名称:fiware-orion,代码行数:21,代码来源:mongoUpdateSubscription.cpp


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