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


C++ bsonobj::iterator类代码示例

本文整理汇总了C++中bsonobj::iterator的典型用法代码示例。如果您正苦于以下问题:C++ iterator类的具体用法?C++ iterator怎么用?C++ iterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: process

	void MongoSchema::process(){
		//std::cout << "Processing " << m_dbname << "." << m_col << std::endl;
		std::string querystr;
		querystr.clear();
		querystr.append(m_dbname);
		querystr.append(".");
		querystr.append(m_col);
		int recordscount = m_conn->count(querystr);
		
		//std::cout << "count:" <<  recordscount << std::endl;
		
		std::auto_ptr<mongo::DBClientCursor> cursor = m_conn->query(querystr, mongo::Query());
		//std::set<std::string> fields;
		while(cursor->more()){
			mongo::BSONObj bo = cursor->next();
			
			for( BSONObj::iterator i = bo.begin(); i.more(); ) { 
				BSONElement e = i.next();
				if(skipField(e.fieldName())){
					continue;
				}
				
				if(e.isSimpleType()){
					hashmap::const_iterator keyexsit = m_map.find(e.fieldName());
					SchemaModel* sm = new SchemaModel();
					if(keyexsit != m_map.end()){
							sm = &m_map[e.fieldName()];
							sm->count ++;
							
					}else{
							sm->count = 1;
							sm->datatype = getType(e);
							m_map[e.fieldName()] = *sm; 
					}
				}else if(e.isABSONObj()){
					int depth = 0;
					std::string parent = e.fieldName();
					extractBSON(e.Obj(), depth, parent);
				}
				
			}			
		}
		BSONObjBuilder bOb;
		BSONArrayBuilder bArr;
		std::tr1::hash<std::string> hashfunc = m_map.hash_function();
		for( hashmap::const_iterator i = m_map.begin(), e = m_map.end() ; i != e ; ++i ) {
			    SchemaModel sm = i->second;
				float percentage = (float)sm.count / (float)recordscount * 100.0;
				std::cout.precision(4);
				BSONObj bo = BSON( "field" << i->first << "percent" << percentage << "datatype" << sm.datatype );
				bArr.append(bo);
		        //std::cout << i->first << " -> "<< "Percent: "<< percentage << " (hash = " << hashfunc( i->first ) << ")" << "\r\n";
		}
		bOb.append(m_col, bArr.arr());
		m_schema = bOb.obj();
	}
开发者ID:soleo,项目名称:MongoAnalytics,代码行数:56,代码来源:MongoSchema.cpp

示例2: compoundObjectResponse

/* ****************************************************************************
*
* compoundObjectResponse -
*/
void compoundObjectResponse(orion::CompoundValueNode* cvP, const BSONElement& be)
{
  BSONObj obj = be.embeddedObject();

  cvP->valueType = orion::ValueTypeObject;
  for (BSONObj::iterator i = obj.begin(); i.more();)
  {
    BSONElement e = i.next();
    addCompoundNode(cvP, e);
  }
}
开发者ID:Findeton,项目名称:fiware-orion,代码行数:15,代码来源:compoundResponses.cpp

示例3: ls

 BSONObj ls(const BSONObj& args) { 
     BSONObj o = listFiles(args);
     if( !o.isEmpty() ) {
         for( BSONObj::iterator i = o.firstElement().Obj().begin(); i.more(); ) { 
             BSONObj f = i.next().Obj();
             cout << f["name"].String();
             if( f["isDirectory"].trueValue() ) cout << '/';
             cout << '\n';
         }
         cout.flush();
     }
     return BSONObj();
 }
开发者ID:jit,项目名称:mongo,代码行数:13,代码来源:shell_utils.cpp

示例4: mongoHeader

void MongoListModel::mongoHeader() const
{
    BSONObj objOne = mongoDatabase->findOne("mongolab_database.random_data",Query());
    mongoHeaderDataList.clear();
    for ( BSONObj::iterator iter = objOne.begin(); iter.more(); )
    {
        BSONElement element = iter.next();
        QString key = QString::fromStdString( element.fieldName() );
        if ( key == "_id" ) continue;
        mongoHeaderDataList.append(key);

    }
}
开发者ID:EriksZviedrans,项目名称:MongoModel,代码行数:13,代码来源:mongolistmodel.cpp

示例5: ls

BSONObj ls(const BSONObj& args, void* data) {
    BSONArrayBuilder ret;
    BSONObj o = listFiles(args, data);
    if (!o.isEmpty()) {
        for (BSONObj::iterator i = o.firstElement().Obj().begin(); i.more();) {
            BSONObj f = i.next().Obj();
            string name = f["name"].String();
            if (f["isDirectory"].trueValue()) {
                name += '/';
            }
            ret << name;
        }
    }
    return BSON("" << ret.arr());
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:15,代码来源:shell_utils_extended.cpp

示例6: Meta2ServerInfo

int Meta2ServerInfo(const TMeta &m, ServerInfo &si)
{
	if(m.data.empty()){
		log(Warn, "meta id:%lld Meta2ServerInfo meta.data empty", m.serverId);
		return -1;
	}
	BSONObj bo(m.data.c_str());
	size_t idx = 0;
	for( BSONObj::iterator i = bo.begin(); i.more() && idx < sizeof(ServerInfoCodec) / sizeof(CodecPair<ServerInfo>); idx++) {
		BSONElement e = i.next();
		int ret = ServerInfoCodec[idx].codec->decode(&si, e);
		if(ret != 0){
			log(Warn, "decode ServerInfo name:%s error occure", ServerInfoCodec[idx].name);
			return -1;
		}
	}
	return 0;
}
开发者ID:zhangchuhu,项目名称:s2s,代码行数:18,代码来源:Meta.cpp

示例7: unmarSessionData

int unmarSessionData(const std::string &xlog, SessionData *info, bool checkName = true)
{
        BSONObj bo(xlog.c_str());
        size_t idx = 0;
        for( BSONObj::iterator i = bo.begin(); i.more() && idx < sizeof(sessionDataCodec) / sizeof(CodecPair<SessionData>); idx++) {
                BSONElement e = i.next();
                if(checkName){
                        if(strcmp(e.fieldName(), sessionDataCodec[idx].name) != 0){
                                myerrno = EDECFIELDMISS;
                                return -1;
                        }
                }
                int ret = sessionDataCodec[idx].codec->decode(info, e);
                if(ret != 0){
                        myerrno = EDECBJSONERR;
                        return -1;
                }
        }
        return 0;
}
开发者ID:zhangchuhu,项目名称:s2s,代码行数:20,代码来源:sessionCodec.cpp

示例8: QUERY

/** Restore transforms from database.
 * @param start_msec start time of range to restore since the epoch in msec
 * @param end_msec end time of range to restore since the epoch in msec
 * @param new_start_msec the new start time since the epoch in msec to which the
 * transform times will be reset, i.e. from the transforms time stamp the
 * @p start time is subtracted and @p new_start is added.
 */
void
MongoDBTransformer::restore(long long start_msec, long long end_msec, long long new_start_msec)
{
  cache_time_ = (double)(end_msec - start_msec) / 1000.;

  if (new_start_msec == 0) {
    new_start_msec = start_msec;
  }

  std::list<std::string> collections =
    mongodb_client_->getCollectionNames(database_);
  
  std::auto_ptr<DBClientCursor> cursor;
  BSONObj doc;
  std::list<std::string>::iterator c;
  for (c = collections.begin(); c != collections.end(); ++c) {
    if ((c->find(database_ + ".TransformInterface.") != 0 ) &&
	(c->find(database_ + ".tf") != 0) )
    {
      continue;
    }

    cursor = mongodb_client_->query(*c,
	     QUERY("timestamp" << GTE << start_msec << LT << end_msec).sort("timestamp"));

    while (cursor->more()) {
      doc = cursor->next();
      if (doc.hasField("transforms")) {
	// multi transforms document
	BSONObj::iterator i = doc.getObjectField("transforms").begin();
	while (i.more()) {
	  BSONElement e = i.next();
	  BSONObj o = e.Obj();
	  restore_tf_doc(o, start_msec, new_start_msec);
	}
     } else {
	restore_tf_doc(doc, start_msec, new_start_msec);
      }
    }
  }
}
开发者ID:tempbottle,项目名称:fawkes,代码行数:48,代码来源:mongodb_tf_transformer.cpp

示例9: extractBSON

	int MongoSchema::extractBSON(mongo::BSONObj bo, int& depth, std::string parent){

		if(depth >= m_depth){
			return 0;
		}
		depth++;
		
		for( BSONObj::iterator i = bo.begin(); i.more(); ) { 
			BSONElement e = i.next();
			
			if(skipField(e.fieldName())){
					continue;
				}

			std::string fieldname = parent ;
			fieldname.append(".");
			fieldname.append(e.fieldName());
			if(e.isSimpleType()){
					hashmap::const_iterator keyexsit = m_map.find(fieldname);
					SchemaModel* sm = new SchemaModel();
					if(keyexsit != m_map.end()){
							sm = &m_map[fieldname];
							sm->count ++;
							
					}else{
							sm->count = 1;
							sm->datatype = getType(e);
							m_map[fieldname] = *sm; 
					}
			 }else if(e.isABSONObj()){
					
					extractBSON(e.Obj(), depth, fieldname);
			}
				
		}
		
		return 0;		
	}
开发者ID:soleo,项目名称:MongoAnalytics,代码行数:38,代码来源:MongoSchema.cpp

示例10: cmdElement

    intrusive_ptr<Pipeline> Pipeline::parseCommand(
        string &errmsg, BSONObj &cmdObj,
        const intrusive_ptr<ExpressionContext> &pCtx) {
        intrusive_ptr<Pipeline> pPipeline(new Pipeline(pCtx));
        vector<BSONElement> pipeline;

        /* gather the specification for the aggregation */
        for(BSONObj::iterator cmdIterator = cmdObj.begin();
                cmdIterator.more(); ) {
            BSONElement cmdElement(cmdIterator.next());
            const char *pFieldName = cmdElement.fieldName();

            // ignore top-level fields prefixed with $. They are for the command processor, not us.
            if (pFieldName[0] == '$') {
                continue;
            }

            /* look for the aggregation command */
            if (!strcmp(pFieldName, commandName)) {
                pPipeline->collectionName = cmdElement.String();
                continue;
            }

            /* check for the collection name */
            if (!strcmp(pFieldName, pipelineName)) {
                pipeline = cmdElement.Array();
                continue;
            }

            /* check for explain option */
            if (!strcmp(pFieldName, explainName)) {
                pPipeline->explain = cmdElement.Bool();
                continue;
            }

            /* if the request came from the router, we're in a shard */
            if (!strcmp(pFieldName, fromRouterName)) {
                pCtx->setInShard(cmdElement.Bool());
                continue;
            }

            /* check for debug options */
            if (!strcmp(pFieldName, splitMongodPipelineName)) {
                pPipeline->splitMongodPipeline = true;
                continue;
            }

            /* we didn't recognize a field in the command */
            ostringstream sb;
            sb <<
               "unrecognized field \"" <<
               cmdElement.fieldName();
            errmsg = sb.str();
            return intrusive_ptr<Pipeline>();
        }

        /*
          If we get here, we've harvested the fields we expect for a pipeline.

          Set up the specified document source pipeline.
        */
        SourceContainer& sources = pPipeline->sources; // shorthand

        /* iterate over the steps in the pipeline */
        const size_t nSteps = pipeline.size();
        for(size_t iStep = 0; iStep < nSteps; ++iStep) {
            /* pull out the pipeline element as an object */
            BSONElement pipeElement(pipeline[iStep]);
            uassert(15942, str::stream() << "pipeline element " <<
                    iStep << " is not an object",
                    pipeElement.type() == Object);
            BSONObj bsonObj(pipeElement.Obj());

            // Parse a pipeline stage from 'bsonObj'.
            uassert(16435, "A pipeline stage specification object must contain exactly one field.",
                    bsonObj.nFields() == 1);
            BSONElement stageSpec = bsonObj.firstElement();
            const char* stageName = stageSpec.fieldName();

            // Create a DocumentSource pipeline stage from 'stageSpec'.
            StageDesc key;
            key.pName = stageName;
            const StageDesc* pDesc = (const StageDesc*)
                    bsearch(&key, stageDesc, nStageDesc, sizeof(StageDesc),
                            stageDescCmp);

            uassert(16436,
                    str::stream() << "Unrecognized pipeline stage name: '" << stageName << "'",
                    pDesc);
            intrusive_ptr<DocumentSource> stage = (*pDesc->pFactory)(&stageSpec, pCtx);
            verify(stage);
            stage->setPipelineStep(iStep);
            sources.push_back(stage);
        }

        /* if there aren't any pipeline stages, there's nothing more to do */
        if (sources.empty())
            return pPipeline;

        /*
//.........这里部分代码省略.........
开发者ID:darkiri,项目名称:mongo,代码行数:101,代码来源:pipeline.cpp

示例11: cmdElement

    intrusive_ptr<Pipeline> Pipeline::parseCommand(
        string &errmsg, BSONObj &cmdObj,
        const intrusive_ptr<ExpressionContext> &pCtx) {
        intrusive_ptr<Pipeline> pPipeline(new Pipeline(pCtx));
        vector<BSONElement> pipeline;

        /* gather the specification for the aggregation */
        for(BSONObj::iterator cmdIterator = cmdObj.begin();
                cmdIterator.more(); ) {
            BSONElement cmdElement(cmdIterator.next());
            const char *pFieldName = cmdElement.fieldName();

            /* look for the aggregation command */
            if (!strcmp(pFieldName, commandName)) {
                pPipeline->collectionName = cmdElement.String();
                continue;
            }

            /* check for the collection name */
            if (!strcmp(pFieldName, pipelineName)) {
                pipeline = cmdElement.Array();
                continue;
            }

            /* check for explain option */
            if (!strcmp(pFieldName, explainName)) {
                pPipeline->explain = cmdElement.Bool();
                continue;
            }

            /* if the request came from the router, we're in a shard */
            if (!strcmp(pFieldName, fromRouterName)) {
                pCtx->setInShard(cmdElement.Bool());
                continue;
            }

            /* check for debug options */
            if (!strcmp(pFieldName, splitMongodPipelineName)) {
                pPipeline->splitMongodPipeline = true;
                continue;
            }

            /* Ignore $auth information sent along with the command. The authentication system will
             * use it, it's not a part of the pipeline.
             */
            if (!strcmp(pFieldName, AuthenticationTable::fieldName.c_str())) {
                continue;
            }

            /* we didn't recognize a field in the command */
            ostringstream sb;
            sb <<
               "unrecognized field \"" <<
               cmdElement.fieldName();
            errmsg = sb.str();
            return intrusive_ptr<Pipeline>();
        }

        /*
          If we get here, we've harvested the fields we expect for a pipeline.

          Set up the specified document source pipeline.
        */
        SourceVector *pSourceVector = &pPipeline->sourceVector; // shorthand

        /* iterate over the steps in the pipeline */
        const size_t nSteps = pipeline.size();
        for(size_t iStep = 0; iStep < nSteps; ++iStep) {
            /* pull out the pipeline element as an object */
            BSONElement pipeElement(pipeline[iStep]);
            uassert(15942, str::stream() << "pipeline element " <<
                    iStep << " is not an object",
                    pipeElement.type() == Object);
            BSONObj bsonObj(pipeElement.Obj());

            // Parse a pipeline stage from 'bsonObj'.
            uassert(16435, "A pipeline stage specification object must contain exactly one field.",
                    bsonObj.nFields() == 1);
            BSONElement stageSpec = bsonObj.firstElement();
            const char* stageName = stageSpec.fieldName();

            // Create a DocumentSource pipeline stage from 'stageSpec'.
            StageDesc key;
            key.pName = stageName;
            const StageDesc* pDesc = (const StageDesc*)
                    bsearch(&key, stageDesc, nStageDesc, sizeof(StageDesc),
                            stageDescCmp);

            uassert(16436,
                    str::stream() << "Unrecognized pipeline stage name: '" << stageName << "'",
                    pDesc);
            intrusive_ptr<DocumentSource> stage = (*pDesc->pFactory)(&stageSpec, pCtx);
            verify(stage);
            stage->setPipelineStep(iStep);
            pSourceVector->push_back(stage);
        }

        /* if there aren't any pipeline stages, there's nothing more to do */
        if (!pSourceVector->size())
            return pPipeline;
//.........这里部分代码省略.........
开发者ID:Xyand,项目名称:mongo,代码行数:101,代码来源:pipeline.cpp


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