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


C++ BSONElementSet类代码示例

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


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

示例1: _match

    bool AllMatchExpression::_match( const BSONElementSet& all ) const {

        if ( all.size() == 0 )
            return _arrayEntries.singleNull();

        const BSONElementSet& equalities = _arrayEntries.equalities();
        for ( BSONElementSet::const_iterator i = equalities.begin(); i != equalities.end(); ++i ) {
            BSONElement foo = *i;
            if ( all.count( foo ) == 0 )
                return false;
        }

        for ( size_t i = 0; i < _arrayEntries.numRegexes(); i++ ) {

            bool found = false;
            for ( BSONElementSet::const_iterator j = all.begin(); j != all.end(); ++j ) {
                BSONElement bar = *j;
                if ( _arrayEntries.regex(i)->matchesSingleElement( bar ) ) {
                    found = true;
                    break;
                }
            }
            if ( ! found )
                return false;

        }

        return true;
    }
开发者ID:gengyit,项目名称:mongo,代码行数:29,代码来源:expression_array.cpp

示例2: getKeys

        void getKeys( const BSONObj &obj, BSONObjSet &keys ) const {

            BSONElement loc = obj.getFieldDotted( _geo );
            if ( loc.eoo() )
                return;

            uassert( 13323 , "latlng not an array" , loc.isABSONObj() );
            string root;
            {
                BSONObjIterator i( loc.Obj() );
                BSONElement x = i.next();
                BSONElement y = i.next();
                root = makeString( hash(x) , hash(y) );
            }


            verify( _other.size() == 1 );

            BSONElementSet all;
            obj.getFieldsDotted( _other[0] , all );

            if ( all.size() == 0 ) {
                _add( obj , root , BSONElement() , keys );
            }
            else {
                for ( BSONElementSet::iterator i=all.begin(); i!=all.end(); ++i ) {
                    _add( obj , root , *i , keys );
                }
            }

        }
开发者ID:89snake89,项目名称:mongo,代码行数:31,代码来源:haystack.cpp

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

示例4: i

    void S2AccessMethod::getKeys(const BSONObj& obj, BSONObjSet* keys) {
        BSONObjSet keysToAdd;
        // We output keys in the same order as the fields we index.
        BSONObjIterator i(_descriptor->keyPattern());
        while (i.more()) {
            BSONElement e = i.next();

            // First, we get the keys that this field adds.  Either they're added literally from
            // the value of the field, or they're transformed if the field is geo.
            BSONElementSet fieldElements;
            // false means Don't expand the last array, duh.
            obj.getFieldsDotted(e.fieldName(), fieldElements, false);

            BSONObjSet keysForThisField;
            if (IndexNames::GEO_2DSPHERE == e.valuestr()) {
                // We can't ever return documents that don't have geometry so don't bother indexing
                // them.
                if (fieldElements.empty()) { return; }
                getGeoKeys(obj, fieldElements, &keysForThisField);
            } else {
                getLiteralKeys(fieldElements, &keysForThisField);
            }

            // We expect there to be the missing field element present in the keys if data is
            // missing.  So, this should be non-empty.
            verify(!keysForThisField.empty());

            // We take the Cartesian product of all of the keys.  This requires that we have
            // some keys to take the Cartesian product with.  If keysToAdd.empty(), we
            // initialize it.  
            if (keysToAdd.empty()) {
                keysToAdd = keysForThisField;
                continue;
            }

            BSONObjSet updatedKeysToAdd;
            for (BSONObjSet::const_iterator it = keysToAdd.begin(); it != keysToAdd.end();
                    ++it) {
                for (BSONObjSet::const_iterator newIt = keysForThisField.begin();
                        newIt!= keysForThisField.end(); ++newIt) {
                    BSONObjBuilder b;
                    b.appendElements(*it);
                    b.append(newIt->firstElement());
                    updatedKeysToAdd.insert(b.obj());
                }
            }
            keysToAdd = updatedKeysToAdd;
        }

        if (keysToAdd.size() > _params.maxKeysPerInsert) {
            warning() << "insert of geo object generated lots of keys (" << keysToAdd.size()
                << ") consider creating larger buckets. obj="
                << obj;
        }

        *keys = keysToAdd;
    }
开发者ID:Axv2,项目名称:mongo,代码行数:57,代码来源:s2_access_method.cpp

示例5: getLiteralKeys

 // elements is a non-geo field.  Add the values literally, expanding arrays.
 void getLiteralKeys(const BSONElementSet &elements, BSONObjSet *out) const {
     if (0 == elements.size()) {
         // Missing fields are indexed as null.
         BSONObjBuilder b;
         b.appendNull("");
         out->insert(b.obj());
     } else {
         for (BSONElementSet::iterator i = elements.begin(); i != elements.end(); ++i) {
             getOneLiteralKey(*i, out);
         }
     }
 }
开发者ID:avish,项目名称:mongo,代码行数:13,代码来源:s2index.cpp

示例6: matches

    bool AllElemMatchOp::matches( const BSONObj& doc, MatchDetails* details ) const {
        BSONElementSet all;
        doc.getFieldsDotted( _path, all, false );

        for ( BSONElementSet::const_iterator i = all.begin(); i != all.end(); ++i ) {
            BSONElement sub = *i;
            if ( sub.type() != Array )
                continue;
            if ( _allMatch( sub.Obj() ) ) {
                return true;
            }
        }
        return false;
    }
开发者ID:gengyit,项目名称:mongo,代码行数:14,代码来源:expression_array.cpp

示例7: uassert

// static
void ExpressionKeysPrivate::getHaystackKeys(const BSONObj& obj,
                                            const std::string& geoField,
                                            const std::vector<std::string>& otherFields,
                                            double bucketSize,
                                            BSONObjSet* keys) {
    BSONElement loc = obj.getFieldDotted(geoField);

    if (loc.eoo()) {
        return;
    }

    // NOTE: We explicitly test nFields >= 2 to support legacy users who may have indexed
    // (intentionally or unintentionally) objects/arrays with more than two fields.
    uassert(16775,
            str::stream() << "cannot extract [lng, lat] array or object from " << obj,
            loc.isABSONObj() && loc.Obj().nFields() >= 2);

    string root;
    {
        BSONObjIterator i(loc.Obj());
        BSONElement x = i.next();
        BSONElement y = i.next();
        root = makeHaystackString(hashHaystackElement(x, bucketSize),
                                  hashHaystackElement(y, bucketSize));
    }

    verify(otherFields.size() == 1);

    BSONElementSet all;

    // This is getFieldsDotted (plural not singular) since the object we're indexing
    // may be an array.
    obj.getFieldsDotted(otherFields[0], all);

    if (all.size() == 0) {
        // We're indexing a document that doesn't have the secondary non-geo field present.
        // XXX: do we want to add this even if all.size() > 0?  result:empty search terms
        // match everything instead of only things w/empty search terms)
        addKey(root, BSONElement(), keys);
    } else {
        // Ex:If our secondary field is type: "foo" or type: {a:"foo", b:"bar"},
        // all.size()==1.  We can query on the complete field.
        // Ex: If our secondary field is type: ["A", "B"] all.size()==2 and all has values
        // "A" and "B".  The query looks for any of the fields in the array.
        for (BSONElementSet::iterator i = all.begin(); i != all.end(); ++i) {
            addKey(root, *i, keys);
        }
    }
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:50,代码来源:expression_keys_private.cpp

示例8: parent

    // Get the index keys for elements that are GeoJSON.
    void S2AccessMethod::getGeoKeys(const BSONElementSet& elements, BSONObjSet* out) const {
        S2RegionCoverer coverer;
        _params.configureCoverer(&coverer);

        // See here for GeoJSON format: geojson.org/geojson-spec.html
        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;
            S2Polyline line;
            S2Cell point;
            // We only support GeoJSON polygons.  Why?:
            // 1. we don't automagically do WGS84/flat -> WGS84, and
            // 2. the old polygon format must die.
            if (GeoParser::isGeoJSONPolygon(obj)) {
                S2Polygon polygon;
                GeoParser::parseGeoJSONPolygon(obj, &polygon);
                keysFromRegion(&coverer, polygon, &cells);
            } else if (GeoParser::parseLineString(obj, &line)) {
                keysFromRegion(&coverer, line, &cells);
            } else if (GeoParser::parsePoint(obj, &point)) {
                S2CellId parent(point.id().parent(_params.finestIndexedLevel));
                cells.push_back(parent.toString());
            } else {
                uasserted(16755, "Can't extract geo keys from object, malformed geometry?:"
                        + obj.toString());
            }
            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:10genReviews,项目名称:mongo,代码行数:47,代码来源:s2_access_method.cpp

示例9: uassert

    // This is the actual search.
    bool S2Cursor::advance() {
        if (_numToReturn <= 0) { return false; }
        for (; _btreeCursor->ok(); _btreeCursor->advance()) {
            ++_nscanned;
            if (_seen.end() != _seen.find(_btreeCursor->currLoc())) { continue; }
            _seen.insert(_btreeCursor->currLoc());

            ++_matchTested;
            MatchDetails details;
            bool matched = _matcher->matchesCurrent(_btreeCursor.get(), &details);
            if (!matched) { continue; }

            const BSONObj &indexedObj = _btreeCursor->currLoc().obj();

            ++_geoTested;
            size_t geoFieldsMatched = 0;
            // OK, cool, non-geo match satisfied.  See if the object actually overlaps w/the geo
            // query fields.
            for (size_t i = 0; i < _fields.size(); ++i) {
                BSONElementSet geoFieldElements;
                indexedObj.getFieldsDotted(_fields[i].getField(), geoFieldElements, false);
                if (geoFieldElements.empty()) { continue; }

                bool match = false;

                for (BSONElementSet::iterator oi = geoFieldElements.begin();
                     !match && (oi != geoFieldElements.end()); ++oi) {
                    if (!oi->isABSONObj()) { continue; }
                    const BSONObj &geoObj = oi->Obj();
                    GeometryContainer geoContainer;
                    uassert(16698, "malformed geometry: " + geoObj.toString(),
                            geoContainer.parseFrom(geoObj));
                    match = _fields[i].satisfiesPredicate(geoContainer);
                }

                if (match) { ++geoFieldsMatched; }
            }

            if (geoFieldsMatched == _fields.size()) {
                // We have a winner!  And we point at it.
                --_numToReturn;
                return true;
            }
        }
        return false;
    }
开发者ID:barriesegal,项目名称:mongo,代码行数:47,代码来源:s2cursor.cpp

示例10: getLiteralKeys

 // elements is a non-geo field.  Add the values literally, expanding arrays.
 void getLiteralKeys(const BSONElementSet &elements, BSONObjSet *out) const {
     if (0 == elements.size()) {
         BSONObjBuilder b;
         b.appendNull("");
         out->insert(b.obj());
     } else if (1 == elements.size()) {
         BSONObjBuilder b;
         b.appendAs(*elements.begin(), "");
         out->insert(b.obj());
     } else {
         BSONArrayBuilder aBuilder;
         for (BSONElementSet::iterator i = elements.begin(); i != elements.end(); ++i) {
             aBuilder.append(*i);
         }
         BSONObjBuilder b;
         b.append("", aBuilder.arr());
         out->insert(b.obj());
     }
 }
开发者ID:ahopedog,项目名称:mongo,代码行数:20,代码来源:s2index.cpp

示例11: getFieldsDotted

    void BSONObj::getFieldsDotted(const char *name, BSONElementSet &ret ) const {
        BSONElement e = getField( name );
        if ( e.eoo() ) {
            const char *p = strchr(name, '.');
            if ( p ) {
                string left(name, p-name);
                const char* next = p+1;
                BSONElement e = getField( left.c_str() );

                if (e.type() == Object){
                    e.embeddedObject().getFieldsDotted(next, ret);
                } else if (e.type() == Array) {
                    bool allDigits = false;
                    if ( isdigit( *next ) ){
                        const char * temp = next + 1;
                        while ( isdigit( *temp ) )
                            temp++;
                        allDigits = *temp == '.';
                    }
                    if (allDigits) {
                        e.embeddedObject().getFieldsDotted(next, ret);
                    } else {
                        BSONObjIterator i(e.embeddedObject());
                        while ( i.more() ){
                            BSONElement e2 = i.next();
                            if (e2.type() == Object || e2.type() == Array)
                                e2.embeddedObject().getFieldsDotted(next, ret);
                        }
                    }
                } else {
                    // do nothing: no match
                }
            }
        } else {
            if (e.type() == Array){
                BSONObjIterator i(e.embeddedObject());
                while ( i.more() )
                    ret.insert(i.next());
            } else {
                ret.insert(e);
            }
        }
    }
开发者ID:erickt,项目名称:mongo,代码行数:43,代码来源:jsobj.cpp

示例12: extractGeometries

    /**
     * Find and parse all geometry elements on the appropriate field path from the document.
     */
    static void extractGeometries(const BSONObj& doc,
                                  const string& path,
                                  vector<StoredGeometry*>* geometries) {

        BSONElementSet geomElements;
        // NOTE: Annoyingly, we cannot just expand arrays b/c single 2d points are arrays, we need
        // to manually expand all results to check if they are geometries
        doc.getFieldsDotted(path, geomElements, false /* expand arrays */);

        for (BSONElementSet::iterator it = geomElements.begin(); it != geomElements.end(); ++it) {

            const BSONElement& el = *it;
            auto_ptr<StoredGeometry> stored(StoredGeometry::parseFrom(el));

            if (stored.get()) {
                // Valid geometry element
                geometries->push_back(stored.release());
            }
            else if (el.type() == Array) {

                // Many geometries may be in an array
                BSONObjIterator arrIt(el.Obj());
                while (arrIt.more()) {

                    const BSONElement nextEl = arrIt.next();
                    stored.reset(StoredGeometry::parseFrom(nextEl));

                    if (stored.get()) {
                        // Valid geometry element
                        geometries->push_back(stored.release());
                    }
                    else {
                        warning() << "geoNear stage read non-geometry element " << nextEl.toString()
                                  << " in array " << el.toString();
                    }
                }
            }
            else {
                warning() << "geoNear stage read non-geometry element " << el.toString();
            }
        }
    }
开发者ID:Mickael-van-der-Beek,项目名称:mongo,代码行数:45,代码来源:geo_near.cpp

示例13: matchesSingleElement

    bool AllMatchExpression::matchesSingleElement( const BSONElement& e ) const {
        if ( _arrayEntries.size() == 0 )
            return false;

        if ( e.eoo() )
            return _arrayEntries.singleNull();

        BSONElementSet all;

        if ( e.type() == Array ) {
            BSONObjIterator i( e.Obj() );
            while ( i.more() ) {
                all.insert( i.next() );
            }
        }
        else {
            // this is the part i want to remove
            all.insert( e );
        }

        return _match( all );
    }
开发者ID:gengyit,项目名称:mongo,代码行数:22,代码来源:expression_array.cpp

示例14: getFieldsDotted

 void BSONObj::getFieldsDotted(const char *name, BSONElementSet &ret, bool *deep ) const {
     BSONElement e = getField( name );
     if ( e.eoo() ) {
         const char *p = strchr(name, '.');
         if ( p ) {
             string left(name, p-name);
             BSONElement e = getField( left );
             if ( e.type() == Array ) {
                 trueDat( deep );
                 BSONObjIterator i( e.embeddedObject() );
                 while( i.more() ) {
                     BSONElement f = i.next();
                     if ( f.eoo() )
                         break;
                     if ( f.type() == Object )
                         f.embeddedObject().getFieldsDotted(p+1, ret);
                 }
             } else if ( e.type() == Object ) {
                 e.embeddedObject().getFieldsDotted(p+1, ret);
             }
         }
     } else {
         if ( e.type() == Array ) {
             trueDat( deep );
             BSONObjIterator i( e.embeddedObject() );
             while( i.more() ) {
                 BSONElement f = i.next();
                 if ( f.eoo() )
                     break;
                 ret.insert( f );
             }
         } else {
             ret.insert( e );
         }
     }
     if ( ret.empty() && deep )
         *deep = false;
 }    
开发者ID:agiamas,项目名称:mongo,代码行数:38,代码来源:jsobj.cpp

示例15: getGeoKeys

        // Get the index keys for elements that are GeoJSON.
        void getGeoKeys(const BSONElementSet &elements, BSONObjSet *out) const {
            S2RegionCoverer coverer;
            _params.configureCoverer(&coverer);

            // See here for GeoJSON format: geojson.org/geojson-spec.html
            for (BSONElementSet::iterator i = elements.begin(); i != elements.end(); ++i) {
                if (!i->isABSONObj()) { continue; }  // error?
                const BSONObj &obj = i->Obj();

                vector<string> cells;
                S2Polygon polygon;
                S2Polyline line;
                S2Cell point;
                if (GeoParser::parsePolygon(obj, &polygon)) {
                    keysFromRegion(&coverer, polygon, &cells);
                } else if (GeoParser::parseLineString(obj, &line)) {
                    keysFromRegion(&coverer, line, &cells);
                } else if (GeoParser::parsePoint(obj, &point)) {
                    keysFromRegion(&coverer, point, &cells);
                } else {
                    uasserted(16572, "Can't extract geo keys from object, malformed geometry?:"
                                     + obj.toString());
                }

                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:ahopedog,项目名称:mongo,代码行数:38,代码来源:s2index.cpp


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