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


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

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


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

示例1: buildGeoNearCmd

BSONObj DocumentSourceGeoNear::buildGeoNearCmd() const {
    // this is very similar to sourceToBson, but slightly different.
    // differences will be noted.

    BSONObjBuilder geoNear;  // not building a subField

    geoNear.append("geoNear", pExpCtx->ns.coll());  // not in toBson

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

    geoNear.append("num", limit);  // called limit in toBson

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

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

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

    if (includeLocs)
        geoNear.append("includeLocs", true);  // String in toBson

    return geoNear.obj();
}
开发者ID:DreamerKing,项目名称:mongo,代码行数:31,代码来源:document_source_geo_near.cpp

示例2: 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

示例3: result

 INT32 rtnSQLAddToSet::result( BSONObjBuilder &builder )
 {
    INT32 rc = SDB_OK;
    PD_CHECK( !_alias.empty(), SDB_INVALIDARG, error, PDERROR,
             "no aliases for function!" );
    try
    {
       builder.appendArray( _alias.toString(), _pArrBuilder->arr() );
       SDB_OSS_DEL _pArrBuilder;
       _fieldSet.clear();
       _objVec.clear();
       _pArrBuilder = SDB_OSS_NEW BSONArrayBuilder();
       PD_CHECK( _pArrBuilder != NULL, SDB_OOM, error, PDERROR,
                "malloc failed" );
    }
    catch( std::exception &e )
    {
       PD_LOG( PDERROR, "received unexpected error:%s", e.what() );
       rc = SDB_SYS;
       goto error;
    }
 done:
    return rc;
 error:
    goto done;
 }
开发者ID:247687009,项目名称:SequoiaDB,代码行数:26,代码来源:rtnSQLAddToSet.cpp

示例4: run

        virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
            string p = cmdObj.firstElement().String();
            if ( p == "*" ) {
                vector<string> names;
                RamLog::getNames( names );

                BSONArrayBuilder arr;
                for ( unsigned i=0; i<names.size(); i++ ) {
                    arr.append( names[i] );
                }
                
                result.appendArray( "names" , arr.arr() );
            }
            else {
                RamLog* ramlog = RamLog::getIfExists(p);
                if ( ! ramlog ) {
                    errmsg = str::stream() << "no RamLog named: " << p;
                    return false;
                }
                RamLog::LineIterator rl(ramlog);

                result.appendNumber( "totalLinesWritten", rl.getTotalLinesWritten() );

                BSONArrayBuilder arr( result.subarrayStart( "log" ) );
                while (rl.more())
                    arr.append(rl.next());
                arr.done();
            }
            return true;
        }
开发者ID:leeon,项目名称:mongo,代码行数:30,代码来源:dbcommands_generic.cpp

示例5: listFiles

 BSONObj listFiles(const BSONObj& args){
     uassert( "need to specify 1 argument to listFiles" , args.nFields() == 1 );
     
     BSONObjBuilder lst;
     
     string rootname = args.firstElement().valuestrsafe();
     path root( rootname );
     
     directory_iterator end;
     directory_iterator i( root);
     
     int num =0;
     while ( i != end ){
         path p = *i;
         
         BSONObjBuilder b;
         b << "name" << p.string();
         b.appendBool( "isDirectory", is_directory( p ) );
         stringstream ss;
         ss << num;
         string name = ss.str();
         lst.append( name.c_str(), b.done() );
         
         num++;
         i++;
     }
     
     BSONObjBuilder ret;
     ret.appendArray( "", lst.done() );
     return ret.obj();
 }
开发者ID:alanw,项目名称:mongo,代码行数:31,代码来源:utils.cpp

示例6: run

        virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
            string p = cmdObj.firstElement().String();
            if ( p == "*" ) {
                vector<string> names;
                RamLog::getNames( names );

                BSONArrayBuilder arr;
                for ( unsigned i=0; i<names.size(); i++ ) {
                    arr.append( names[i] );
                }
                
                result.appendArray( "names" , arr.arr() );
            }
            else {
                RamLog* rl = RamLog::get( p );
                if ( ! rl ) {
                    errmsg = str::stream() << "no RamLog named: " << p;
                    return false;
                }

                result.appendNumber( "totalLinesWritten", rl->getTotalLinesWritten() );

                vector<const char*> lines;
                rl->get( lines );

                BSONArrayBuilder arr( result.subarrayStart( "log" ) );
                for ( unsigned i=0; i<lines.size(); i++ )
                    arr.append( lines[i] );
                arr.done();
            }
            return true;
        }
开发者ID:NathanZamecnik,项目名称:mongo,代码行数:32,代码来源:dbcommands_generic.cpp

示例7: append

    void Projection::append( BSONObjBuilder& b , const BSONElement& e ) const {
        FieldMap::const_iterator field = _fields.find( e.fieldName() );

        if (field == _fields.end()) {
            if (_include)
                b.append(e);
        }
        else {
            Projection& subfm = *field->second;

            if ((subfm._fields.empty() && !subfm._special) || !(e.type()==Object || e.type()==Array) ) {
                if (subfm._include)
                    b.append(e);
            }
            else if (e.type() == Object) {
                BSONObjBuilder subb;
                BSONObjIterator it(e.embeddedObject());
                while (it.more()) {
                    subfm.append(subb, it.next());
                }
                b.append(e.fieldName(), subb.obj());

            }
            else { //Array
                BSONObjBuilder subb;
                subfm.appendArray(subb, e.embeddedObject());
                b.appendArray(e.fieldName(), subb.obj());
            }
        }
    }
开发者ID:Desartstudio,项目名称:mongo-nonx86,代码行数:30,代码来源:projection.cpp

示例8: build

 BSONObj build( int depth ){
     BSONObjBuilder b;
     b.append( "0" , depth );
     if ( depth > 0 )
         b.appendArray( "1" , build( depth - 1 ) );
     return b.obj();
 }
开发者ID:hashrocket,项目名称:mongo,代码行数:7,代码来源:jstests.cpp

示例9: writeExplainShard

    void Pipeline::writeExplainShard(BSONObjBuilder &result) const {
        BSONArrayBuilder opArray; // where we'll put the pipeline ops

        // next, add the pipeline operators
        writeExplainOps(&opArray);

        result.appendArray(serverPipelineName, opArray.arr());
    }
开发者ID:darkiri,项目名称:mongo,代码行数:8,代码来源:pipeline.cpp

示例10: 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

示例11: run

        virtual bool run(OperationContext* txn,
                         const string& ,
                         BSONObj& cmdObj,
                         int, string& errmsg,
                         BSONObjBuilder& result,
                         bool fromRepl) {

            BSONObj configObj;
            if( cmdObj["replSetInitiate"].type() == Object ) {
                configObj = cmdObj["replSetInitiate"].Obj();
            }

            if (configObj.isEmpty()) {
                result.append("info2", "no configuration explicitly specified -- making one");
                log() << "replSet info initiate : no configuration specified.  "
                    "Using a default configuration for the set";

                ReplicationCoordinatorExternalStateImpl externalState;
                std::string name;
                std::vector<HostAndPort> seeds;
                std::set<HostAndPort> seedSet;
                parseReplSetSeedList(
                        &externalState,
                        getGlobalReplicationCoordinator()->getSettings().replSet,
                        name,
                        seeds,
                        seedSet); // may throw...

                BSONObjBuilder b;
                b.append("_id", name);
                b.append("version", 1);
                BSONObjBuilder members;
                HostAndPort me = someHostAndPortForMe();
                members.append("0", BSON( "_id" << 0 << "host" << me.toString() ));
                result.append("me", me.toString());
                for( unsigned i = 0; i < seeds.size(); i++ ) {
                    members.append(BSONObjBuilder::numStr(i+1),
                                   BSON( "_id" << i+1 << "host" << seeds[i].toString()));
                }
                b.appendArray("members", members.obj());
                configObj = b.obj();
                log() << "replSet created this configuration for initiation : " <<
                        configObj.toString();
            }

            if (configObj.getField("version").eoo()) {
                // Missing version field defaults to version 1.
                BSONObjBuilder builder;
                builder.appendElements(configObj);
                builder.append("version", 1);
                configObj = builder.obj();
            }

            Status status = getGlobalReplicationCoordinator()->processReplSetInitiate(txn,
                                                                                      configObj,
                                                                                      &result);
            return appendCommandStatus(result, status);
        }
开发者ID:3rf,项目名称:mongo,代码行数:58,代码来源:replset_commands.cpp

示例12: run

    bool GroupCommand::run(OperationContext* txn,
                           const std::string& dbname,
                           BSONObj& cmdObj,
                           int,
                           std::string& errmsg,
                           BSONObjBuilder& out,
                           bool fromRepl) {
        GroupRequest groupRequest;
        Status parseRequestStatus = parseRequest(dbname, cmdObj, &groupRequest);
        if (!parseRequestStatus.isOK()) {
            return appendCommandStatus(out, parseRequestStatus);
        }

        AutoGetCollectionForRead ctx(txn, groupRequest.ns);
        Collection* coll = ctx.getCollection();

        PlanExecutor *rawPlanExecutor;
        Status getExecStatus = getExecutorGroup(txn,
                                                coll,
                                                groupRequest,
                                                PlanExecutor::YIELD_AUTO,
                                                &rawPlanExecutor);
        if (!getExecStatus.isOK()) {
            return appendCommandStatus(out, getExecStatus);
        }

        scoped_ptr<PlanExecutor> planExecutor(rawPlanExecutor);

        // Group executors return ADVANCED exactly once, with the entire group result.
        BSONObj retval;
        PlanExecutor::ExecState state = planExecutor->getNext(&retval, NULL);
        if (PlanExecutor::ADVANCED != state) {
            if (PlanExecutor::FAILURE == state &&
                WorkingSetCommon::isValidStatusMemberObject(retval)) {
                return appendCommandStatus(out, WorkingSetCommon::getMemberObjectStatus(retval));
            }
            return appendCommandStatus(out,
                                       Status(ErrorCodes::BadValue,
                                              str::stream() << "error encountered during group "
                                                            << "operation, executor returned "
                                                            << PlanExecutor::statestr(state)));
        }
        invariant(planExecutor->isEOF());

        invariant(STAGE_GROUP == planExecutor->getRootStage()->stageType());
        GroupStage* groupStage = static_cast<GroupStage*>(planExecutor->getRootStage());
        const GroupStats* groupStats =
            static_cast<const GroupStats*>(groupStage->getSpecificStats());
        const CommonStats* groupChildStats = groupStage->getChildren()[0]->getCommonStats();

        out.appendArray("retval", retval);
        out.append("count", static_cast<long long>(groupChildStats->advanced));
        out.append("keys", static_cast<long long>(groupStats->nGroups));

        return true;
    }
开发者ID:lalford,项目名称:mongo,代码行数:56,代码来源:group.cpp

示例13: eval

 bool DBClientWithCommands::eval(const string &dbname, const string &jscode, BSONObj& info, BSONElement& retValue, BSONObj *args) {
     BSONObjBuilder b;
     b.appendCode("$eval", jscode.c_str());
     if ( args )
         b.appendArray("args", *args);
     bool ok = runCommand(dbname, b.done(), info);
     if ( ok )
         retValue = info.getField("retval");
     return ok;
 }
开发者ID:tanfulai,项目名称:mongo,代码行数:10,代码来源:dbclient.cpp

示例14: buildOpMsg

 INT32 rtnCoordDelete::buildOpMsg( const CoordCataInfoPtr &cataInfo,
                                  const CoordSubCLlist &subCLList,
                                  CHAR *pSrcMsg, CHAR *&pDstMsg,
                                  INT32 &bufferSize )
 {
    INT32 rc = SDB_OK;
    INT32 flag;
    CHAR *pCollectionName = NULL;
    CHAR *pDeletor = NULL;
    CHAR *pHint = NULL;
    BSONObj boDeletor;
    BSONObj boHint;
    rc = msgExtractDelete( pSrcMsg, &flag, &pCollectionName,
                         &pDeletor, &pHint );
    PD_RC_CHECK( rc, PDERROR,
                "failed to parse delete request(rc=%d)",
                rc );
    try
    {
       boDeletor = BSONObj( pDeletor );
       boHint = BSONObj( pHint );
       BSONArrayBuilder babSubCL;
       CoordSubCLlist::const_iterator iterCL = subCLList.begin();
       while( iterCL != subCLList.end() )
       {
          babSubCL.append( *iterCL );
          ++iterCL;
       }
       BSONObjBuilder bobNewDeletor;
       bobNewDeletor.appendElements( boDeletor );
       bobNewDeletor.appendArray( CAT_SUBCL_NAME, babSubCL.arr() );
       BSONObj boNewDeletor = bobNewDeletor.obj();
       rc = msgBuildDeleteMsg( &pDstMsg, &bufferSize, pCollectionName,
                               flag, 0, &boNewDeletor, &boHint );
       PD_RC_CHECK( rc, PDERROR,
                   "failed to build delete request(rc=%d)",
                   rc );
       {
       MsgOpDelete *pReqMsg = (MsgOpDelete *)pDstMsg;
       MsgOpDelete *pSrcReq = (MsgOpDelete *)pSrcMsg;
       pReqMsg->version = cataInfo->getVersion();
       pReqMsg->w = pSrcReq->w;
       }
    }
    catch ( std::exception &e )
    {
       PD_RC_CHECK( SDB_INVALIDARG, PDERROR,
                   "occur unexpected error:%s",
                   e.what() );
    }
 done:
    return rc;
 error:
    goto done;
 }
开发者ID:Niwalker,项目名称:SequoiaDB,代码行数:55,代码来源:rtnCoordDelete.cpp

示例15: append

    void Projection::append( BSONObjBuilder& b , const BSONElement& e, const MatchDetails* details,
                             const ArrayOpType arrayOpType ) const {

        FieldMap::const_iterator field = _fields.find( e.fieldName() );
        if (field == _fields.end()) {
            if (_include)
                b.append(e);
        }
        else {
            Projection& subfm = *field->second;
            if ( ( subfm._fields.empty() && !subfm._special ) ||
                 !(e.type()==Object || e.type()==Array) ) {
                // field map empty, or element is not an array/object
                if (subfm._include)
                    b.append(e);
            }
            else if (e.type() == Object) {
                BSONObjBuilder subb;
                BSONObjIterator it(e.embeddedObject());
                while (it.more()) {
                    subfm.append(subb, it.next(), details, arrayOpType);
                }
                b.append(e.fieldName(), subb.obj());
            }
            else { //Array
                BSONObjBuilder matchedBuilder;
                if ( details && ( arrayOpType == ARRAY_OP_POSITIONAL ||
                        arrayOpType == ARRAY_OP_POSITIONAL_KEYED )) {
                    // $ positional operator specified

                    LOG(4) << "projection: checking if element " << e << " matched spec: "
                           << getSpec() << " match details: " << *details << endl;
                    uassert( 16352, mongoutils::str::stream() << "positional operator ("
                                        << e.fieldName()
                                        << ".$) requires corresponding field in query specifier",
                                   details && details->hasElemMatchKey() );

                    uassert( 16353, "positional operator element mismatch",
                             ! e.embeddedObject()[details->elemMatchKey()].eoo() );

                    // append as the first element in the projected array
                    matchedBuilder.appendAs( e.embeddedObject()[details->elemMatchKey()], "0" );
                    // append the key as the second element in the projected array
                    if ( arrayOpType == ARRAY_OP_POSITIONAL_KEYED ) {
                        matchedBuilder.append( "1", details->elemMatchKey() );
                    }
                }
                else {
                    // append exact array; no subarray matcher specified
                    subfm.appendArray( matchedBuilder, e.embeddedObject() );
                }
                b.appendArray( e.fieldName(), matchedBuilder.obj() );
            }
        }
    }
开发者ID:suokko,项目名称:mongo,代码行数:55,代码来源:projection.cpp


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