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


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

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


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

示例1: _init

    void IndexSpec::_init(){
        assert( keyPattern.objsize() );
        
        string pluginName = IndexPlugin::findPluginName( keyPattern );
        
        BSONObjBuilder nullKeyB;
        BSONObjIterator i( keyPattern );
        
        while( i.more() ) {
            BSONElement e = i.next();
            _fieldNames.push_back( e.fieldName() );
            _fixed.push_back( BSONElement() );
            nullKeyB.appendNull( "" );            
        }
        
        _nullKey = nullKeyB.obj();

        BSONObjBuilder b;
        b.appendNull( "" );
        _nullObj = b.obj();
        _nullElt = _nullObj.firstElement();
        
        if ( pluginName.size() ){
            IndexPlugin * plugin = IndexPlugin::get( pluginName );
            if ( ! plugin ){
                log() << "warning: can't find plugin [" << pluginName << "]" << endl;
            }
            else {
                _indexType.reset( plugin->generate( this ) );
            }
        }
        _finishedInit = true;
    }
开发者ID:joshrotenberg,项目名称:mongo,代码行数:33,代码来源:indexkey.cpp

示例2: appendSelf

bool LastError::appendSelf(BSONObjBuilder& b, bool blankErr) const {
    if (!_valid) {
        if (blankErr)
            b.appendNull("err");
        b.append("n", 0);
        return false;
    }

    if (_msg.empty()) {
        if (blankErr) {
            b.appendNull("err");
        }
    } else {
        b.append("err", _msg);
    }

    if (_code) {
        b.append("code", _code);
        b.append("codeName", ErrorCodes::errorString(ErrorCodes::Error(_code)));
    }
    if (_updatedExisting != NotUpdate)
        b.appendBool("updatedExisting", _updatedExisting == True);
    if (!_upsertedId.isEmpty()) {
        b.append(_upsertedId[kUpsertedFieldName]);
    }
    b.appendNumber("n", _nObjects);

    return !_msg.empty();
}
开发者ID:i80and,项目名称:mongo,代码行数:29,代码来源:lasterror.cpp

示例3: append

    void append( BSONObjBuilder& b , string name , jsval val , BSONType oldType = EOO , int depth=0 ) {
        //cout << "name: " << name << "\t" << typeString( val ) << " oldType: " << oldType << endl;
        switch ( JS_TypeOfValue( _context , val ) ) {

        case JSTYPE_VOID:
            b.appendUndefined( name.c_str() );
            break;
        case JSTYPE_NULL:
            b.appendNull( name.c_str() );
            break;

        case JSTYPE_NUMBER: {
            double d = toNumber( val );
            if ( oldType == NumberInt && ((int)d) == d )
                b.append( name.c_str() , (int)d );
            else
                b.append( name.c_str() , d );
            break;
        }
        case JSTYPE_STRING:
            b.append( name.c_str() , toString( val ) );
            break;
        case JSTYPE_BOOLEAN:
            b.appendBool( name.c_str() , toBoolean( val ) );
            break;

        case JSTYPE_OBJECT: {
            JSObject * o = JSVAL_TO_OBJECT( val );
            if ( ! o || o == JSVAL_NULL ) {
                b.appendNull( name.c_str() );
            }
            else if ( ! appendSpecialDBObject( this , b , name , val , o ) ) {
                BSONObj sub = toObject( o , depth );
                if ( JS_IsArrayObject( _context , o ) ) {
                    b.appendArray( name.c_str() , sub );
                }
                else {
                    b.append( name.c_str() , sub );
                }
            }
            break;
        }

        case JSTYPE_FUNCTION: {
            string s = toString(val);
            if ( s[0] == '/' ) {
                appendRegex( b , name , s );
            }
            else {
                b.appendCode( name.c_str() , getFunctionCode( val ).c_str() );
            }
            break;
        }

        default:
            uassert( 10217 ,  (string)"can't append field.  name:" + name + " type: " + typeString( val ) , 0 );
        }
    }
开发者ID:xrogaan,项目名称:mongo,代码行数:58,代码来源:engine_spidermonkey.cpp

示例4: _init

    void IndexSpec::_init() {
        verify( keyPattern.objsize() );

        // some basics
        _nFields = keyPattern.nFields();
        _sparse = info["sparse"].trueValue();
        uassert( 13529 , "sparse only works for single field keys" , ! _sparse || _nFields );


        {
            // build _nullKey

            BSONObjBuilder b;
            BSONObjIterator i( keyPattern );

            while( i.more() ) {
                BSONElement e = i.next();
                _fieldNames.push_back( e.fieldName() );
                _fixed.push_back( BSONElement() );
                b.appendNull( "" );
            }
            _nullKey = b.obj();
        }

        {
            // _nullElt
            BSONObjBuilder b;
            b.appendNull( "" );
            _nullObj = b.obj();
            _nullElt = _nullObj.firstElement();
        }

        {
            // _undefinedElt
            BSONObjBuilder b;
            b.appendUndefined( "" );
            _undefinedObj = b.obj();
            _undefinedElt = _undefinedObj.firstElement();
        }
        
        {
            // handle plugins
            string pluginName = IndexPlugin::findPluginName( keyPattern );
            if ( pluginName.size() ) {
                IndexPlugin * plugin = IndexPlugin::get( pluginName );
                if ( ! plugin ) {
                    log() << "warning: can't find plugin [" << pluginName << "]" << endl;
                }
                else {
                    _indexType.reset( plugin->generate( this ) );
                }
            }
        }

        _finishedInit = true;
    }
开发者ID:LeeShuni,项目名称:mongo,代码行数:56,代码来源:indexkey.cpp

示例5:

    BtreeKeyGenerator::BtreeKeyGenerator(vector<const char*> fieldNames, vector<BSONElement> fixed, 
                                         bool isSparse)
        : _fieldNames(fieldNames), _isSparse(isSparse), _fixed(fixed) {

        BSONObjBuilder nullKeyBuilder;
        for (size_t i = 0; i < fieldNames.size(); ++i) {
            nullKeyBuilder.appendNull("");
        }
        _nullKey = nullKeyBuilder.obj();

        BSONObjBuilder nullEltBuilder;
        nullEltBuilder.appendNull("");
        _nullObj = nullEltBuilder.obj();
        _nullElt = _nullObj.firstElement();
    }
开发者ID:Cassie90,项目名称:mongo,代码行数:15,代码来源:btree_key_generator.cpp

示例6: appendCommandResponse

void appendCommandResponse(PlanExecutor* exec,
                           bool isRemove,
                           const boost::optional<BSONObj>& value,
                           BSONObjBuilder& result) {
    BSONObjBuilder lastErrorObjBuilder(result.subobjStart("lastErrorObject"));

    if (isRemove) {
        lastErrorObjBuilder.appendNumber("n", getDeleteStats(exec)->docsDeleted);
    } else {
        const UpdateStats* updateStats = getUpdateStats(exec);
        lastErrorObjBuilder.appendBool("updatedExisting", updateStats->nMatched > 0);
        lastErrorObjBuilder.appendNumber("n", updateStats->inserted ? 1 : updateStats->nMatched);
        // Note we have to use the objInserted from the stats here, rather than 'value'
        // because the _id field could have been excluded by a projection.
        if (!updateStats->objInserted.isEmpty()) {
            lastErrorObjBuilder.appendAs(updateStats->objInserted["_id"], kUpsertedFieldName);
        }
    }
    lastErrorObjBuilder.done();

    if (value) {
        result.append("value", *value);
    } else {
        result.appendNull("value");
    }
}
开发者ID:mihail812,项目名称:mongo,代码行数:26,代码来源:find_and_modify.cpp

示例7: result

   INT32 _rtnSQLMax::result( BSONObjBuilder &builder )
   {
      INT32 rc = SDB_OK ;

      try
      {
         if ( _ele.eoo() )
         {
            builder.appendNull( _alias.toString() ) ;
         }
         else
         {
            builder.appendAs( _ele, _alias.toString() ) ;
         }

         _obj = BSONObj() ;
         _ele = BSONElement() ;
      }
      catch ( std::exception &e )
      {
         PD_LOG( PDERROR, "unexcepted err happened:%s",
                 e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
开发者ID:247687009,项目名称:SequoiaDB,代码行数:31,代码来源:rtnSQLMax.cpp

示例8: getMissingField

// static
BSONObj IndexLegacy::getMissingField(OperationContext* opCtx,
                                     Collection* collection,
                                     const BSONObj& infoObj) {
    BSONObj keyPattern = infoObj.getObjectField("key");
    std::string accessMethodName;
    if (collection)
        accessMethodName = collection->getIndexCatalog()->getAccessMethodName(opCtx, keyPattern);
    else
        accessMethodName = IndexNames::findPluginName(keyPattern);

    if (IndexNames::HASHED == accessMethodName) {
        int hashVersion = infoObj["hashVersion"].numberInt();
        HashSeed seed = infoObj["seed"].numberInt();

        // Explicit null valued fields and missing fields are both represented in hashed indexes
        // using the hash value of the null BSONElement.  This is partly for historical reasons
        // (hash of null was used in the initial release of hashed indexes and changing would
        // alter the data format).  Additionally, in certain places the hashed index code and
        // the index bound calculation code assume null and missing are indexed identically.
        BSONObj nullObj = BSON("" << BSONNULL);
        return BSON("" << ExpressionKeysPrivate::makeSingleHashKey(
                        nullObj.firstElement(), seed, hashVersion));
    } else {
        BSONObjBuilder b;
        b.appendNull("");
        return b.obj();
    }
}
开发者ID:DINKIN,项目名称:mongo,代码行数:29,代码来源:index_legacy.cpp

示例9: Timestamp

void KVCatalog::FeatureTracker::putInfo(OperationContext* opCtx, const FeatureBits& versionInfo) {
    BSONObjBuilder bob;
    bob.appendBool(kIsFeatureDocumentFieldName, true);
    // We intentionally include the "ns" field with a null value in the feature document to prevent
    // older versions that do 'obj["ns"].String()' from starting up. This way only versions that are
    // aware of the feature document's existence can successfully start up.
    bob.appendNull(kNamespaceFieldName);
    bob.append(kNonRepairableFeaturesFieldName,
               static_cast<long long>(versionInfo.nonRepairableFeatures));
    bob.append(kRepairableFeaturesFieldName,
               static_cast<long long>(versionInfo.repairableFeatures));
    BSONObj obj = bob.done();

    if (_rid.isNull()) {
        // This is the first time a feature is being marked as in-use or not in-use, so we must
        // insert the feature document rather than update it.
        const bool enforceQuota = false;
        // TODO SERVER-30638: using timestamp 0 for these inserts
        auto rid = _catalog->_rs->insertRecord(
            opCtx, obj.objdata(), obj.objsize(), Timestamp(), enforceQuota);
        fassert(40113, rid.getStatus());
        _rid = rid.getValue();
    } else {
        const bool enforceQuota = false;
        UpdateNotifier* notifier = nullptr;
        auto status = _catalog->_rs->updateRecord(
            opCtx, _rid, obj.objdata(), obj.objsize(), enforceQuota, notifier);
        fassert(40114, status);
    }
}
开发者ID:zhihuiFan,项目名称:mongo,代码行数:30,代码来源:kv_catalog.cpp

示例10: OK

MONGO_INITIALIZER(FTSIndexFormat)(InitializerContext* context) {
    BSONObjBuilder b;
    b.appendNull("");
    nullObj = b.obj();
    nullElt = nullObj.firstElement();
    return Status::OK();
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:7,代码来源:fts_index_format.cpp

示例11: idBob

BSONObj RollbackFixUpInfo::SingleDocumentOperationDescription::toBSON() const {
    // For non-insert operations, we will use the collection UUID and document id to query the sync
    // source (using the source collection's default collation) for the most recent copy of the
    // deleted/updated document. This is necessary to complete the rollback for a deleted/updated
    // document.
    // Insert operations are rolled back by deleting the the document from the local collection.
    BSONObjBuilder bob;
    {
        BSONObjBuilder idBob(bob.subobjStart("_id"));
        _collectionUuid.appendToBuilder(&idBob, "collectionUuid");
        idBob.append(_wrappedDocId.firstElement());
    }

    // This matches the "op" field in the oplog entry.
    appendOpTypeToBuilder(_opType, &bob);

    // The database name is used in the find command request when fetching the document from the
    // sync source.
    bob.append("db", _dbName);

    // This will be replaced by the most recent copy of the affected document from the sync
    // source. If the document is not found on the sync source, this will remain null.
    bob.appendNull("documentToRestore");

    return bob.obj();
}
开发者ID:bjori,项目名称:mongo,代码行数:26,代码来源:rollback_fix_up_info_descriptions.cpp

示例12: uassert

    // Get the index keys for elements that are GeoJSON.
    void S2AccessMethod::getGeoKeys(const BSONElementSet& elements, BSONObjSet* out) const {
        for (BSONElementSet::iterator i = elements.begin(); i != elements.end(); ++i) {
            uassert(16754, "Can't parse geometry from element: " + i->toString(),
                    i->isABSONObj());
            const BSONObj &obj = i->Obj();

            vector<string> cells;
            bool succeeded = S2SearchUtil::getKeysForObject(obj, _params, &cells);
            uassert(16755, "Can't extract geo keys from object, malformed geometry?:"
                           + obj.toString(), succeeded);

            uassert(16756, "Unable to generate keys for (likely malformed) geometry: "
                    + obj.toString(),
                    cells.size() > 0);

            for (vector<string>::const_iterator it = cells.begin(); it != cells.end(); ++it) {
                BSONObjBuilder b;
                b.append("", *it);
                out->insert(b.obj());
            }
        }

        if (0 == out->size()) {
            BSONObjBuilder b;
            b.appendNull("");
            out->insert(b.obj());
        }
    }
开发者ID:MediaMath,项目名称:mongo,代码行数:29,代码来源:s2_access_method.cpp

示例13: getPrivilegeDocument

    Status AuthzManagerExternalState::getPrivilegeDocument(const UserName& userName,
                                                           int authzVersion,
                                                           BSONObj* result) {
        if (userName == internalSecurity.user->getName()) {
            return Status(ErrorCodes::InternalError,
                          "Requested privilege document for the internal user");
        }

        StringData dbname = userName.getDB();

        // Make sure the dbname is actually a database
        if (dbname == StringData("$external", StringData::LiteralTag()) ||
            dbname == AuthorizationManager::SERVER_RESOURCE_NAME ||
            dbname == AuthorizationManager::CLUSTER_RESOURCE_NAME) {
            return Status(ErrorCodes::UserNotFound,
                          mongoutils::str::stream() << "No privilege documents stored in the " <<
                          dbname << " user source.");
        }

        if (!NamespaceString::validDBName(dbname)) {
            return Status(ErrorCodes::BadValue,
                          mongoutils::str::stream() << "Bad database name \"" << dbname << "\"");
        }

        // Build the query needed to get the privilege document
        std::string usersNamespace;
        BSONObjBuilder queryBuilder;
        if (authzVersion == 1) {
            usersNamespace = mongoutils::str::stream() << dbname << ".system.users";
            queryBuilder.append(AuthorizationManager::V1_USER_NAME_FIELD_NAME, userName.getUser());
            queryBuilder.appendNull(AuthorizationManager::V1_USER_SOURCE_FIELD_NAME);
        } else if (authzVersion == 2) {
            usersNamespace = "admin.system.users";
            queryBuilder.append(AuthorizationManager::USER_NAME_FIELD_NAME, userName.getUser());
            queryBuilder.append(AuthorizationManager::USER_SOURCE_FIELD_NAME, userName.getDB());
        } else {
            return Status(ErrorCodes::UnsupportedFormat,
                          mongoutils::str::stream() <<
                                  "Unrecognized authorization format version: " << authzVersion);
        }

        // Query for the privilege document
        BSONObj userBSONObj;
        Status found = _findUser(usersNamespace, queryBuilder.obj(), &userBSONObj);
        if (!found.isOK()) {
            if (found.code() == ErrorCodes::UserNotFound) {
                // Return more detailed status that includes user name.
                return Status(ErrorCodes::UserNotFound,
                              mongoutils::str::stream() << "auth: couldn't find user " <<
                                      userName.toString() << ", " << usersNamespace,
                              0);
            } else {
                return found;
            }
        }

        *result = userBSONObj.getOwned();
        return Status::OK();
    }
开发者ID:man27382210,项目名称:mongo,代码行数:59,代码来源:authz_manager_external_state.cpp

示例14: getPrivilegeDocument

    Status AuthzManagerExternalState::getPrivilegeDocument(const std::string& dbname,
                                                           const UserName& userName,
                                                           BSONObj* result) const {

        if (dbname == StringData("$external", StringData::LiteralTag()) ||
            dbname == AuthorizationManager::SERVER_RESOURCE_NAME ||
            dbname == AuthorizationManager::CLUSTER_RESOURCE_NAME) {
            return Status(ErrorCodes::UserNotFound,
                          mongoutils::str::stream() << "No privilege documents stored in the " <<
                          dbname << " user source.");
        }

        if (!NamespaceString::validDBName(dbname)) {
            return Status(ErrorCodes::BadValue, "Bad database name \"" + dbname + "\"");
        }

        if (userName == internalSecurity.user) {
            if (internalSecurity.pwd.empty()) {
                return Status(ErrorCodes::UserNotFound,
                              "key file must be used to log in with internal user",
                              15889);
            }
            *result = BSON(AuthorizationManager::USER_NAME_FIELD_NAME <<
                           internalSecurity.user.getUser() <<
                           AuthorizationManager::PASSWORD_FIELD_NAME <<
                           internalSecurity.pwd).getOwned();
            return Status::OK();
        }

        std::string usersNamespace = dbname + ".system.users";

        BSONObj userBSONObj;
        BSONObjBuilder queryBuilder;
        queryBuilder.append(AuthorizationManager::USER_NAME_FIELD_NAME, userName.getUser());
        if (userName.getDB() == dbname) {
            queryBuilder.appendNull(AuthorizationManager::USER_SOURCE_FIELD_NAME);
        }
        else {
            queryBuilder.append(AuthorizationManager::USER_SOURCE_FIELD_NAME,
                                userName.getDB());
        }

        Status found = _findUser(usersNamespace, queryBuilder.obj(), &userBSONObj);
        if (!found.isOK()) {
            if (found.code() == ErrorCodes::UserNotFound) {
                // Return more detailed status that includes user name.
                return Status(ErrorCodes::UserNotFound,
                              mongoutils::str::stream() << "auth: couldn't find user " <<
                                      userName.toString() << ", " << usersNamespace,
                              0);
            } else {
                return found;
            }
        }

        *result = userBSONObj.getOwned();
        return Status::OK();
    }
开发者ID:duraidxg,项目名称:mongo,代码行数:58,代码来源:authz_manager_external_state.cpp

示例15: Status

    Status AuthzManagerExternalState::getPrivilegeDocumentV1(const StringData& dbname,
                                                             const UserName& userName,
                                                             BSONObj* result) {
        if (userName == internalSecurity.user->getName()) {
            return Status(ErrorCodes::InternalError,
                          "Requested privilege document for the internal user");
        }

        if (!NamespaceString::validDBName(dbname)) {
            return Status(ErrorCodes::BadValue,
                          mongoutils::str::stream() << "Bad database name \"" << dbname << "\"");
        }

        const bool isUserFromTargetDB = (dbname == userName.getDB());

        // Build the query needed to get the privilege document

        BSONObjBuilder queryBuilder;
        const NamespaceString usersNamespace(dbname, "system.users");
        queryBuilder.append(AuthorizationManager::V1_USER_NAME_FIELD_NAME, userName.getUser());
        if (isUserFromTargetDB) {
            queryBuilder.appendNull(AuthorizationManager::V1_USER_SOURCE_FIELD_NAME);
        }
        else {
            queryBuilder.append(AuthorizationManager::V1_USER_SOURCE_FIELD_NAME, userName.getDB());
        }

        // Query for the privilege document
        BSONObj userBSONObj;
        Status found = findOne(usersNamespace, queryBuilder.done(), &userBSONObj);
        if (!found.isOK()) {
            if (found.code() == ErrorCodes::NoMatchingDocument) {
                // Return more detailed status that includes user name.
                return Status(ErrorCodes::UserNotFound,
                              mongoutils::str::stream() << "auth: couldn't find user " <<
                              userName.toString() << ", " << usersNamespace.ns(),
                              0);
            } else {
                return found;
            }
        }

        if (isUserFromTargetDB) {
            if (userBSONObj[AuthorizationManager::PASSWORD_FIELD_NAME].eoo()) {
                return Status(ErrorCodes::AuthSchemaIncompatible, mongoutils::str::stream() <<
                              "User documents with schema version " <<
                              AuthorizationManager::schemaVersion24 <<
                              " must have a \"" <<
                              AuthorizationManager::PASSWORD_FIELD_NAME <<
                              "\" field.");
            }
        }

        *result = userBSONObj.getOwned();
        return Status::OK();
    }
开发者ID:504com,项目名称:mongo,代码行数:56,代码来源:authz_manager_external_state.cpp


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