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


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

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


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

示例1: paraseUserStockCfg

int paraseUserStockCfg(BSONObj obj,std::vector<user_stock_cfg>& uscarray)
{
	std::string uid = obj.getStringField("Uid");
	std::vector<BSONElement> elements = obj["stocks"].Array();
	std::vector<BSONElement>::iterator it = elements.begin();
	int count = 0;
	for(; it != elements.end(); ++it)
	{
		BSONObj stock = it->Obj();
		user_stock_cfg usc;
		usc.uid = uid;
		usc.stock = stock.getStringField("stock");
		usc.bulletin = stock.getIntField("bulletin");
		if(stock.getField("max_price").ok())
			usc.max_price = stock.getField("max_price").Double();
		else
			usc.max_price = -0.111;
		
		if(stock.getField("min_price").ok())
			usc.min_price = stock.getField("min_price").Double();
		else
			usc.min_price = -0.111;
	
		usc.run = stock.getIntField("run");
		uscarray.push_back(usc);
		count++;
	}
	return count ;
}
开发者ID:7zkeeper,项目名称:emcds,代码行数:29,代码来源:BSONCreator.cpp

示例2: readFromDB

/**********************************************************
 *see readFromDB in FileRec, similar structure
 * 
***********************************************************/
void VersionRec::readFromDB(mongo::DBClientConnection& conn, string versionID) {

    auto_ptr<mongo::DBClientCursor> cursor =
            conn.query("fileRecords.FileVersion", MONGO_QUERY("_id" << mongo::OID(versionID)));

    if (cursor->more()) {
        //convert to VersionRec
        BSONObj record = cursor->next();
        this->versionid = versionID;
        this->tmpname = record.getStringField("Tempname");
        this->filehash = record.getStringField("filehash");
        this->length = record.getIntField("length");
        this->modifytime.tv_nsec = record.getField("Mtnsec").numberLong();
        this->modifytime.tv_sec = record.getField("mtsec").numberLong();
        this->versionnumber = record.getIntField("Version");

        //similar to the comments collection in readfromDB in FileRec
        vector<BSONElement> hashes(record.getField("Blktable").Array());
        for (vector<BSONElement>::iterator it = hashes.begin(); it != hashes.end(); ++it) {

            BSONObj blockdata = it->Obj();
            BSONElement blocknum = blockdata.getField("Blknum");
            BSONElement blockhash = blockdata.getField("hash");

            VersionDiffBlock tmp;
            tmp.blockNo = blocknum.Int();
            tmp.blockHash = blockhash.String();
            changesAppend(tmp);
        }
    }
    else{
        cout << "could not find version " << versionID << endl;
    }
}
开发者ID:matthewschwarze,项目名称:csci222,代码行数:38,代码来源:VersionRec.cpp

示例3: parseMobileToken

void parseMobileToken(BSONObj obj,mobile_apptypes& app)
{
	app.token = obj.getStringField("Token");
	if(obj.getField("incrementID").ok())
		app.incrementID = obj.getField("incrementID").Long();
	else
		app.incrementID = -1;
	app.osversion = obj.getStringField("osversion");
	app.comment = obj.getStringField("comment");

	std::vector<BSONElement> elements = obj["apptypes"].Array();
	std::vector<BSONElement>::iterator it = elements.begin();

	for(; it != elements.end(); ++it)
	{
		BSONObj appobj = it->Obj();
		apptypeinfo appinfo;
		appinfo.apptype = appobj.getIntField("apptype");		
		if(appobj.getField("flag").ok())
			appinfo.flag = appobj.getIntField("flag");
		else 
			appinfo.flag = 0;
		appinfo.lastuid = appobj.getStringField("lastuid");
		if(appobj.getField("lasttime").ok())
			appinfo.lasttime = appobj.getField("lasttime").Long();
		else
			appinfo.lasttime = 0;
		appinfo.appversion = appobj.getStringField("appversion");
		app.apptypes.push_back(appinfo);
	}
}
开发者ID:7zkeeper,项目名称:emcds,代码行数:31,代码来源:BSONCreator.cpp

示例4: readFromDB

/**********************************************************
 *reads from db and converts bson to FileRec object
 * 
***********************************************************/
void FileRec::readFromDB(mongo::DBClientConnection& conn, string filename) {

    boost::filesystem::path p(filename); //get filename from path
    string file(p.filename().c_str());
    auto_ptr<mongo::DBClientCursor> cursor = conn.query("fileRecords.Filerec", MONGO_QUERY("filename" << file));

    if (cursor->more()) {

        BSONObj record = cursor->next();
        //get data from db and store in the FileRec
        this->filename = record.getStringField("filename");
        this->tempname = record.getStringField("Tempname");
        this->recentHash = record.getStringField("curhash");
        this->origHash = record.getStringField("ovhash");
        this->length = record.getIntField("length");
        this->versionCount = record.getIntField("nversions");
        this->modifytime.tv_nsec = record.getField("Mtnsec").numberLong();
        this->modifytime.tv_sec = record.getField("mtsec").numberLong();
        this->refNum = record.getIntField("currentversion");

        vector<BSONElement> hashes(record.getField("FileBlkHashes").Array());
        for (vector<BSONElement>::iterator it = hashes.begin(); it != hashes.end(); ++it) {
            appendBlock((*it).String());
        }

        //comments is an array of objects so it takes a bit of nesting to convert
        vector<BSONElement> array = record["comments"].Array(); //convert to array
        for (vector<BSONElement>::iterator ar = array.begin(); ar != array.end(); ++ar) {
            BSONObj commentdata = ar->Obj(); //store object at array[x] into BSONObj
            BSONElement version = commentdata.getField("version"); //convert
            BSONElement commentdb = commentdata.getField("comment");

            comment data;
            data.comment = commentdb.String();
            data.version = version.Int();
            appendComment(data);
        }


        if (record.hasElement("versionrec")) { //again an array of objects
            vector<BSONElement> array = record["versionrec"].Array();
            for (vector<BSONElement>::iterator it = array.begin(); it != array.end(); ++it) {

                BSONObj versionRecord = it->Obj();
                BSONElement id = versionRecord.getField("id");
                appendVersion(id.String());
            }
        } 
    }
}
开发者ID:matthewschwarze,项目名称:csci222,代码行数:54,代码来源:FileRec.cpp

示例5: fuzzFile

        /**
         * @param args - [ name, byte index ]
         * In this initial implementation, all bits in the specified byte are flipped.
         */
        BSONObj fuzzFile(const BSONObj& args, void* data) {
            uassert( 13619, "fuzzFile takes 2 arguments", args.nFields() == 2 );
            scoped_ptr< File > f( new File() );
            f->open( args.getStringField( "0" ) );
            uassert( 13620, "couldn't open file to fuzz", !f->bad() && f->is_open() );

            char c;
            f->read( args.getIntField( "1" ), &c, 1 );
            c = ~c;
            f->write( args.getIntField( "1" ), &c, 1 );

            return undefinedReturn;
            // f close is implicit
        }
开发者ID:89snake89,项目名称:mongo,代码行数:18,代码来源:shell_utils_extended.cpp

示例6: run

 virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     string fromhost = cmdObj.getStringField("from");
     if ( fromhost.empty() ) {
         errmsg = "missing from spec";
         return false;
     }
     string collection = cmdObj.getStringField("cloneCollection");
     if ( collection.empty() ) {
         errmsg = "missing cloneCollection spec";
         return false;
     }
     BSONObj query = cmdObj.getObjectField("query");
     if ( query.isEmpty() )
         query = BSONObj();
     BSONElement copyIndexesSpec = cmdObj.getField("copyindexes");
     bool copyIndexes = copyIndexesSpec.isBoolean() ? copyIndexesSpec.boolean() : true;
     // Will not be used if doesn't exist.
     int logSizeMb = cmdObj.getIntField( "logSizeMb" );
     
     /* replication note: we must logOp() not the command, but the cloned data -- if the slave
      were to clone it would get a different point-in-time and not match.
      */
     setClient( collection.c_str() );
     
     log() << "cloneCollection.  db:" << ns << " collection:" << collection << " from: " << fromhost << " query: " << query << " logSizeMb: " << logSizeMb << ( copyIndexes ? "" : ", not copying indexes" ) << endl;
     
     Cloner c;
     long long cursorId;
     if ( !c.startCloneCollection( fromhost.c_str(), collection.c_str(), query, errmsg, !fromRepl, copyIndexes, logSizeMb, cursorId ) )
         return false;
     return c.finishCloneCollection( fromhost.c_str(), collection.c_str(), query, cursorId, errmsg);
 }
开发者ID:gregglind,项目名称:mongo,代码行数:32,代码来源:cloner.cpp

示例7: ExecuteEarlyProcess

bool CCentralizeZbxEventProcessor::ExecuteEarlyProcess(BSONObj boRecord)
{
	auto_ptr<DBClientCursor> ptrTriggerDataCursor;
	BSONObj boTriggerRecord;
	int iPriority;
	iPriority = 0;
	Query queryCondition = QUERY("triggerid" << boRecord["triggerid"] << "zabbix_server_id" << boRecord["zabbix_server_id"]);
	m_pTriggerLogController->Find(ptrTriggerDataCursor, queryCondition);
	if (ptrTriggerDataCursor->more())
	{
		boTriggerRecord = ptrTriggerDataCursor->nextSafe();
	}

	/*-- Check Trigger Info --*/
	if (boTriggerRecord.isEmpty())
	{
		return false;
	}
	iPriority = boTriggerRecord.hasField("priority") ? boTriggerRecord.getIntField("priority") : 0;
	if (5 != iPriority)
	{
		return false;
	}
	return true;
}
开发者ID:hieutrtr,项目名称:DataTransfer,代码行数:25,代码来源:CentralizeZbxEventProcessor.cpp

示例8: run

        virtual bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
            string coll = cmdObj[ "captrunc" ].valuestrsafe();
            uassert( 13416, "captrunc must specify a collection", !coll.empty() );
            NamespaceString nss( dbname, coll );
            int n = cmdObj.getIntField( "n" );
            bool inc = cmdObj.getBoolField( "inc" ); // inclusive range?

            Client::WriteContext ctx(txn,  nss.ns() );
            Collection* collection = ctx.getCollection();
            massert( 13417, "captrunc collection not found or empty", collection);

            RecordId end;
            {
                boost::scoped_ptr<PlanExecutor> exec(InternalPlanner::collectionScan(txn,
                                                                                     nss.ns(),
                                                                                     collection,
                                                                                     InternalPlanner::BACKWARD));
                // We remove 'n' elements so the start is one past that
                for( int i = 0; i < n + 1; ++i ) {
                    PlanExecutor::ExecState state = exec->getNext(NULL, &end);
                    massert( 13418, "captrunc invalid n", PlanExecutor::ADVANCED == state);
                }
            }
            WriteUnitOfWork wuow(txn);
            collection->temp_cappedTruncateAfter( txn, end, inc );
            wuow.commit();
            return true;
        }
开发者ID:ramgtv,项目名称:mongo,代码行数:28,代码来源:test_commands.cpp

示例9: q

std::vector<post> StorageEngine::getposts(int number) {
    std::vector<post> posts;
    collection = "posts";
    update_namespace();
    //if it's empty, return nothing.
    try {
        if(con.count(namespacestr) == 0)
            return posts;
        Query q("{ }");
        auto_ptr<DBClientCursor> cursor = con.query(namespacestr,q.sort("timestamp",-1));
        while(cursor->more()) {
            BSONObj record = cursor->next();
            post newpost;
            newpost.title = record.getStringField("title");
            newpost.body = record.getStringField("body");
            newpost.timestamp = record.getIntField("timestamp");
            newpost.oid = getoid(record);
            posts.push_back(newpost);
        }
    } catch( DBException &e ) {
        cout << "caught " << e.what() << endl;
        exit(0);
    }
    

    return posts;
}
开发者ID:mich181189,项目名称:MongoBlog,代码行数:27,代码来源:StorageEngine.cpp

示例10: run

    virtual bool run(OperationContext* opCtx,
                     const string& dbname,
                     const BSONObj& cmdObj,
                     BSONObjBuilder& result) {
        const NamespaceString fullNs = CommandHelpers::parseNsCollectionRequired(dbname, cmdObj);
        if (!fullNs.isValid()) {
            return CommandHelpers::appendCommandStatus(
                result,
                {ErrorCodes::InvalidNamespace,
                 str::stream() << "collection name " << fullNs.ns() << " is not valid"});
        }

        int n = cmdObj.getIntField("n");
        bool inc = cmdObj.getBoolField("inc");  // inclusive range?

        if (n <= 0) {
            return CommandHelpers::appendCommandStatus(
                result, {ErrorCodes::BadValue, "n must be a positive integer"});
        }

        // Lock the database in mode IX and lock the collection exclusively.
        AutoGetCollection autoColl(opCtx, fullNs, MODE_IX, MODE_X);
        Collection* collection = autoColl.getCollection();
        if (!collection) {
            return CommandHelpers::appendCommandStatus(
                result,
                {ErrorCodes::NamespaceNotFound,
                 str::stream() << "collection " << fullNs.ns() << " does not exist"});
        }

        if (!collection->isCapped()) {
            return CommandHelpers::appendCommandStatus(
                result, {ErrorCodes::IllegalOperation, "collection must be capped"});
        }

        RecordId end;
        {
            // Scan backwards through the collection to find the document to start truncating from.
            // We will remove 'n' documents, so start truncating from the (n + 1)th document to the
            // end.
            auto exec = InternalPlanner::collectionScan(
                opCtx, fullNs.ns(), collection, PlanExecutor::NO_YIELD, InternalPlanner::BACKWARD);

            for (int i = 0; i < n + 1; ++i) {
                PlanExecutor::ExecState state = exec->getNext(nullptr, &end);
                if (PlanExecutor::ADVANCED != state) {
                    return CommandHelpers::appendCommandStatus(
                        result,
                        {ErrorCodes::IllegalOperation,
                         str::stream() << "invalid n, collection contains fewer than " << n
                                       << " documents"});
                }
            }
        }

        collection->cappedTruncateAfter(opCtx, end, inc);

        return true;
    }
开发者ID:zhihuiFan,项目名称:mongo,代码行数:59,代码来源:test_commands.cpp

示例11:

TEST(QueryTest, Sort) {
    Query q;
    q.sort(BSON("a" << 1));
    ASSERT_TRUE(q.isComplex());
    BSONObj sort = q.getSort();
    ASSERT_TRUE(sort.hasField("a"));
    ASSERT_EQUALS(sort.getIntField("a"), 1);
}
开发者ID:MaheshOruganti,项目名称:mongo-cxx-driver-legacy-1.1.0,代码行数:8,代码来源:query_test.cpp

示例12: ns

 unsigned long long DBClientWithCommands::count(const string &_ns, BSONObj query) { 
     NamespaceString ns(_ns);
     BSONObj cmd = BSON( "count" << ns.coll << "query" << query );
     BSONObj res;
     if( !runCommand(ns.db.c_str(), cmd, res) )
         uasserted(string("count fails:") + res.toString());
     return res.getIntField("n");
 }
开发者ID:tanfulai,项目名称:mongo,代码行数:8,代码来源:dbclient.cpp

示例13: _setModified

    /**
     * SERVER-13001 - mixed sharded cluster could return nModified
     * (servers >= 2.6) or not (servers <= 2.4). If any call does
     * not return nModified we cannot report a valid final count.
     */
    void WriteResult::_setModified(const BSONObj& result) {
        int nModified = result.getIntField("nModified");

        if (_hasModifiedCount && nModified >= 0)
            _nModified += nModified;
        else
            _hasModifiedCount = false;
    }
开发者ID:weakwater,项目名称:easy,代码行数:13,代码来源:write_result.cpp

示例14: toStatusString

// static
std::string WorkingSetCommon::toStatusString(const BSONObj& obj) {
    if (!isValidStatusMemberObject(obj)) {
        Status unknownStatus(ErrorCodes::UnknownError, "no details available");
        return unknownStatus.toString();
    }
    Status status(ErrorCodes::fromInt(obj.getIntField("code")), obj.getStringField("errmsg"));
    return status.toString();
}
开发者ID:AnkyrinRepeat,项目名称:mongo,代码行数:9,代码来源:working_set_common.cpp

示例15: availableOptions

 enum QueryOptions DBClientWithCommands::availableOptions() {
     if ( !_haveCachedAvailableOptions ) {
         BSONObj ret;
         if ( runCommand( "admin", BSON( "availablequeryoptions" << 1 ), ret ) ) {
             _cachedAvailableOptions = ( enum QueryOptions )( ret.getIntField( "options" ) );
         }
         _haveCachedAvailableOptions = true;
     }
     return _cachedAvailableOptions;
 }
开发者ID:RyokoAkizuki,项目名称:freshcity,代码行数:10,代码来源:dbclient.cpp


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