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


C++ BSONElement::isSimpleType方法代码示例

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


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

示例1: isSimpleIdQuery

// static
bool CanonicalQuery::isSimpleIdQuery(const BSONObj& query) {
    bool hasID = false;

    BSONObjIterator it(query);
    while (it.more()) {
        BSONElement elt = it.next();
        if (str::equals("_id", elt.fieldName())) {
            // Verify that the query on _id is a simple equality.
            hasID = true;

            if (elt.type() == Object) {
                // If the value is an object, it can't have a query operator
                // (must be a literal object match).
                if (elt.Obj().firstElementFieldName()[0] == '$') {
                    return false;
                }
            } else if (!elt.isSimpleType() && BinData != elt.type()) {
                // The _id fild cannot be something like { _id : { $gt : ...
                // But it can be BinData.
                return false;
            }
        } else if (elt.fieldName()[0] == '$' && (str::equals("$isolated", elt.fieldName()) ||
                                                 str::equals("$atomic", elt.fieldName()))) {
            // ok, passthrough
        } else {
            // If the field is not _id, it must be $isolated/$atomic.
            return false;
        }
    }

    return hasID;
}
开发者ID:hcj1991pp,项目名称:mongo,代码行数:33,代码来源:canonical_query.cpp

示例2: isSimpleIdQuery

    // Copied verbatim from queryutil.cpp.
    static bool isSimpleIdQuery(const BSONObj& query) {
        BSONObjIterator it(query);

        if (!it.more()) {
            return false;
        }

        BSONElement elt = it.next();

        if (it.more()) {
            return false;
        }

        if (strcmp("_id", elt.fieldName()) != 0) {
            return false;
        }

        // e.g. not something like { _id : { $gt : ...
        if (elt.isSimpleType()) {
            return true;
        }

        if (elt.type() == Object) {
            return elt.Obj().firstElementFieldName()[0] != '$';
        }

        return false;
    }
开发者ID:balyanrobin,项目名称:mongo,代码行数:29,代码来源:query_planner.cpp

示例3: isSimpleIdQuery

    // Copied verbatim from queryutil.cpp.
    static bool isSimpleIdQuery(const BSONObj& query) {
        // Just one field name.
        BSONObjIterator it(query);
        if (!it.more()) { return false; }

        BSONElement elt = it.next();
        if (it.more()) { return false; }

        // Which is _id...
        if (strcmp("_id", elt.fieldName()) != 0) {
            return false;
        }

        // And not something like { _id : { $gt : ...
        if (elt.isSimpleType()) { return true; }

        // BinData is OK too.
        if (BinData == elt.type()) { return true; }

        // And if the value is an object...
        if (elt.type() == Object) {
            // Can't do this.
            return elt.Obj().firstElementFieldName()[0] != '$';
        }

        return false;
    }
开发者ID:godouxm,项目名称:mongo,代码行数:28,代码来源:get_runner.cpp

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

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


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