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


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

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


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

示例1: modifiedRangeBound

    BSONObj Helpers::modifiedRangeBound( const BSONObj& bound ,
                                         const BSONObj& keyPattern ,
                                         int minOrMax ){
        BSONObjBuilder newBound;

        BSONObjIterator src( bound );
        BSONObjIterator pat( keyPattern );

        while( src.more() ){
            massert( 16341 ,
                     str::stream() << "keyPattern " << keyPattern
                                   << " shorter than bound " << bound ,
                     pat.more() );
            BSONElement srcElt = src.next();
            BSONElement patElt = pat.next();
            massert( 16333 ,
                     str::stream() << "field names of bound " << bound
                                   << " do not match those of keyPattern " << keyPattern ,
                     str::equals( srcElt.fieldName() , patElt.fieldName() ) );
            newBound.appendAs( srcElt , "" );
        }
        while( pat.more() ){
            BSONElement patElt = pat.next();
            verify( patElt.isNumber() );
            if( minOrMax * patElt.numberInt() == 1){
                newBound.appendMaxKey("");
            }
            else {
                newBound.appendMinKey("");
            }
        }
        return newBound.obj();
    }
开发者ID:89snake89,项目名称:mongo,代码行数:33,代码来源:dbhelpers.cpp

示例2: modifiedRangeBound

    BSONObj Helpers::modifiedRangeBound( const BSONObj& bound ,
                                         const BSONObj& keyPattern ,
                                         int minOrMax ){
        BSONObjBuilder newBound;

        BSONObjIterator src( bound );
        BSONObjIterator pat( keyPattern );

        while( src.more() ){
            BSONElement srcElt = src.next();
            BSONElement patElt = pat.next();
            massert( 16333 , "bound " + bound.toString() +
                             "not extendible to pattern" + keyPattern.toString(),
                     strcmp( srcElt.fieldName() , patElt.fieldName() ) == 0 );
            newBound.appendAs( srcElt , "" );
        }
        while( pat.more() ){
            BSONElement patElt = pat.next();
            verify( patElt.isNumber() );
            if( minOrMax * patElt.numberInt() == 1){
                newBound.appendMaxKey("");
            }
            else {
                newBound.appendMinKey("");
            }
        }
        return newBound.obj();
    }
开发者ID:phelipemaia,项目名称:mongo,代码行数:28,代码来源:dbhelpers.cpp

示例3: run

        void run(){
            Scope * s = globalScriptEngine->createScope();

            BSONObjBuilder b;
            b.appendTimestamp( "a" , 123456789 );
            b.appendMinKey( "b" );
            b.appendMaxKey( "c" );
            b.appendTimestamp( "d" , 1234000 , 9876 );
            

            {
                BSONObj t = b.done();
                ASSERT_EQUALS( 1234000U , t["d"].timestampTime() );
                ASSERT_EQUALS( 9876U , t["d"].timestampInc() );
            }

            s->setObject( "z" , b.obj() );
            
            ASSERT( s->invoke( "y = { a : z.a , b : z.b , c : z.c , d: z.d }" , BSONObj() ) == 0 );

            BSONObj out = s->getObject( "y" );
            ASSERT_EQUALS( Timestamp , out["a"].type() );
            ASSERT_EQUALS( MinKey , out["b"].type() );
            ASSERT_EQUALS( MaxKey , out["c"].type() );
            ASSERT_EQUALS( Timestamp , out["d"].type() );

            ASSERT_EQUALS( 9876U , out["d"].timestampInc() );
            ASSERT_EQUALS( 1234000U , out["d"].timestampTime() );
            ASSERT_EQUALS( 123456789U , out["a"].date() );


            delete s;
        }
开发者ID:hashrocket,项目名称:mongo,代码行数:33,代码来源:jstests.cpp

示例4: allValuesForField

 // static
 void IndexBoundsBuilder::allValuesForField(const BSONElement& elt, OrderedIntervalList* out) {
     // ARGH, BSONValue would make this shorter.
     BSONObjBuilder bob;
     bob.appendMinKey("");
     bob.appendMaxKey("");
     out->name = elt.fieldName();
     out->intervals.push_back(makeRangeInterval(bob.obj(), true, true));
 }
开发者ID:ChrisKozak,项目名称:mongo,代码行数:9,代码来源:index_bounds_builder.cpp

示例5: allValuesForField

    // static
    void IndexBoundsBuilder::allValuesForField(const BSONElement& elt, OrderedIntervalList* out) {
        // ARGH, BSONValue would make this shorter.
        BSONObjBuilder bob;
        if (-1 == elt.number()) {
            // Index should go from MaxKey to MinKey as it's descending.
            bob.appendMaxKey("");
            bob.appendMinKey("");
        }
        else {
            // Index goes from MinKey to MaxKey as it's ascending.
            bob.appendMinKey("");
            bob.appendMaxKey("");
        }

        out->name = elt.fieldName();
        out->intervals.push_back(makeRangeInterval(bob.obj(), true, true));
    }
开发者ID:ryannutley,项目名称:mongo,代码行数:18,代码来源:index_bounds_builder.cpp

示例6: finishMinObj

/**
 * "Finishes" the min object for the $min query option by filling in an empty object with
 * MinKey/MaxKey and stripping field names.
 *
 * In the case that 'minObj' is empty, we "finish" it by filling in either MinKey or MaxKey
 * instead. Choosing whether to use MinKey or MaxKey is done by comparing against 'maxObj'.
 * For instance, suppose 'minObj' is empty, 'maxObj' is { a: 3 }, and the key pattern is
 * { a: -1 }. According to the key pattern ordering, { a: 3 } < MinKey. This means that the
 * proper resulting bounds are
 *
 *   start: { '': MaxKey }, end: { '': 3 }
 *
 * as opposed to
 *
 *   start: { '': MinKey }, end: { '': 3 }
 *
 * Suppose instead that the key pattern is { a: 1 }, with the same 'minObj' and 'maxObj'
 * (that is, an empty object and { a: 3 } respectively). In this case, { a: 3 } > MinKey,
 * which means that we use range [{'': MinKey}, {'': 3}]. The proper 'minObj' in this case is
 * MinKey, whereas in the previous example it was MaxKey.
 *
 * If 'minObj' is non-empty, then all we do is strip its field names (because index keys always
 * have empty field names).
 */
static BSONObj finishMinObj(const BSONObj& kp, const BSONObj& minObj, const BSONObj& maxObj) {
    BSONObjBuilder bob;
    bob.appendMinKey("");
    BSONObj minKey = bob.obj();

    if (minObj.isEmpty()) {
        if (0 > minKey.woCompare(maxObj, kp, false)) {
            BSONObjBuilder minKeyBuilder;
            minKeyBuilder.appendMinKey("");
            return minKeyBuilder.obj();
        } else {
            BSONObjBuilder maxKeyBuilder;
            maxKeyBuilder.appendMaxKey("");
            return maxKeyBuilder.obj();
        }
    } else {
        return stripFieldNames(minObj);
    }
}
开发者ID:m4rcsch,项目名称:mongo,代码行数:43,代码来源:query_planner.cpp

示例7: complement

    // static
    void OrderedIntervalList::complement() {
        BSONObjBuilder minBob;
        minBob.appendMinKey("");
        BSONObj minObj = minBob.obj();

        // We complement by scanning the entire range of BSON values
        // from MinKey to MaxKey. The value from which we must begin
        // the next complemented interval is kept in 'curBoundary'.
        BSONElement curBoundary = minObj.firstElement();

        // If 'curInclusive' is true, then 'curBoundary' is
        // included in one of the original intervals, and hence
        // should not be included in the complement (and vice-versa
        // if 'curInclusive' is false).
        bool curInclusive = false;

        // We will build up a list of intervals that represents
        // the inversion of those in the OIL.
        vector<Interval> newIntervals;
        for (size_t j = 0; j < intervals.size(); ++j) {
            Interval curInt = intervals[j];
            if (0 != curInt.start.woCompare(curBoundary) ||
                (!curInclusive && !curInt.startInclusive)) {
                // Make a new interval from 'curBoundary' to
                // the start of 'curInterval'.
                BSONObjBuilder intBob;
                intBob.append(curBoundary);
                intBob.append(curInt.start);
                Interval newInt(intBob.obj(), !curInclusive, !curInt.startInclusive);
                newIntervals.push_back(newInt);
            }

            // Reset the boundary for the next iteration.
            curBoundary = curInt.end;
            curInclusive = curInt.endInclusive;
        }

        // We may have to add a final interval which ends in MaxKey.
        BSONObjBuilder maxBob;
        maxBob.appendMaxKey("");
        BSONObj maxObj = maxBob.obj();
        BSONElement maxKey = maxObj.firstElement();
        if (0 != maxKey.woCompare(curBoundary) || !curInclusive) {
            BSONObjBuilder intBob;
            intBob.append(curBoundary);
            intBob.append(maxKey);
            Interval newInt(intBob.obj(), !curInclusive, true);
            newIntervals.push_back(newInt);
        }

        // Replace the old list of intervals with the new one.
        intervals.clear();
        intervals.insert(intervals.end(), newIntervals.begin(), newIntervals.end());
    }
开发者ID:7segments,项目名称:mongo-1,代码行数:55,代码来源:index_bounds.cpp

示例8: finishMinObj

/**
 * "Finishes" the min object for the $min query option by filling in an empty object with
 * MinKey/MaxKey and stripping field names. Also translates keys according to the collation, if
 * necessary.
 *
 * In the case that 'minObj' is empty, we "finish" it by filling in either MinKey or MaxKey
 * instead. Choosing whether to use MinKey or MaxKey is done by comparing against 'maxObj'.
 * For instance, suppose 'minObj' is empty, 'maxObj' is { a: 3 }, and the key pattern is
 * { a: -1 }. According to the key pattern ordering, { a: 3 } < MinKey. This means that the
 * proper resulting bounds are
 *
 *   start: { '': MaxKey }, end: { '': 3 }
 *
 * as opposed to
 *
 *   start: { '': MinKey }, end: { '': 3 }
 *
 * Suppose instead that the key pattern is { a: 1 }, with the same 'minObj' and 'maxObj'
 * (that is, an empty object and { a: 3 } respectively). In this case, { a: 3 } > MinKey,
 * which means that we use range [{'': MinKey}, {'': 3}]. The proper 'minObj' in this case is
 * MinKey, whereas in the previous example it was MaxKey.
 *
 * If 'minObj' is non-empty, then all we do is strip its field names (because index keys always
 * have empty field names).
 */
static BSONObj finishMinObj(const IndexEntry& indexEntry,
                            const BSONObj& minObj,
                            const BSONObj& maxObj) {
    BSONObjBuilder bob;
    bob.appendMinKey("");
    BSONObj minKey = bob.obj();

    if (minObj.isEmpty()) {
        if (0 > minKey.woCompare(maxObj, indexEntry.keyPattern, false)) {
            BSONObjBuilder minKeyBuilder;
            minKeyBuilder.appendMinKey("");
            return minKeyBuilder.obj();
        } else {
            BSONObjBuilder maxKeyBuilder;
            maxKeyBuilder.appendMaxKey("");
            return maxKeyBuilder.obj();
        }
    } else {
        return stripFieldNamesAndApplyCollation(minObj, indexEntry.collator);
    }
}
开发者ID:i80and,项目名称:mongo,代码行数:46,代码来源:query_planner.cpp

示例9: run

        bool run(const string& dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
            const char* ns = jsobj.getStringField( "splitVector" );
            BSONObj keyPattern = jsobj.getObjectField( "keyPattern" );

            BSONObj min = jsobj.getObjectField( "min" );
            BSONObj max = jsobj.getObjectField( "max" );
            if ( min.isEmpty() && max.isEmpty() ){
                BSONObjBuilder minBuilder;
                BSONObjBuilder maxBuilder;
                BSONForEach(key, keyPattern){
                    minBuilder.appendMinKey( key.fieldName() );
                    maxBuilder.appendMaxKey( key.fieldName() );
                }
开发者ID:mapleoin,项目名称:mongo,代码行数:13,代码来源:d_split.cpp

示例10: it

    ShardKeyPattern::ShardKeyPattern( BSONObj p ) : pattern( p.getOwned() ) {
        pattern.getFieldNames(patternfields);

        BSONObjBuilder min;
        BSONObjBuilder max;

        BSONObjIterator it(p);
        while (it.more()) {
            BSONElement e (it.next());
            min.appendMinKey(e.fieldName());
            max.appendMaxKey(e.fieldName());
        }

        gMin = min.obj();
        gMax = max.obj();
    }
开发者ID:tanakh,项目名称:mongo,代码行数:16,代码来源:shardkey.cpp

示例11: toBSON

    BSONObj IndexBounds::toBSON() const {
        BSONObjBuilder builder;
        if (isSimpleRange) {
            // TODO
        }
        else {
            for (vector<OrderedIntervalList>::const_iterator itField = fields.begin();
                 itField != fields.end();
                 ++itField) {
                BSONArrayBuilder fieldBuilder(builder.subarrayStart(itField->name));
                for (vector<Interval>::const_iterator itInterval = itField->intervals.begin();
                     itInterval != itField->intervals.end();
                     ++itInterval) {
                    BSONArrayBuilder intervalBuilder;

                    // Careful to output $minElement/$maxElement if we don't have bounds.
                    if (itInterval->start.eoo()) {
                        BSONObjBuilder minBuilder;
                        minBuilder.appendMinKey("");
                        BSONObj minKeyObj = minBuilder.obj();
                        intervalBuilder.append(minKeyObj.firstElement());
                    }
                    else {
                        intervalBuilder.append(itInterval->start);
                    }

                    if (itInterval->end.eoo()) {
                        BSONObjBuilder maxBuilder;
                        maxBuilder.appendMaxKey("");
                        BSONObj maxKeyObj = maxBuilder.obj();
                        intervalBuilder.append(maxKeyObj.firstElement());
                    }
                    else {
                        intervalBuilder.append(itInterval->end);
                    }

                    fieldBuilder.append(
                        static_cast<BSONArray>(intervalBuilder.arr().clientReadable()));
                }
            }
        }
        return builder.obj();
    }
开发者ID:ashleybrener,项目名称:mongo,代码行数:43,代码来源:index_bounds.cpp

示例12: run

        bool run(const string& dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){

            //
            // 1.a We'll parse the parameters in two steps. First, make sure the we can use the split index to get
            //     a good approximation of the size of the chunk -- without needing to access the actual data.
            //

            const char* ns = jsobj.getStringField( "splitVector" );
            BSONObj keyPattern = jsobj.getObjectField( "keyPattern" );

            // If min and max are not provided use the "minKey" and "maxKey" for the sharding key pattern.
            BSONObj min = jsobj.getObjectField( "min" );
            BSONObj max = jsobj.getObjectField( "max" );
            if ( min.isEmpty() && max.isEmpty() ){
                BSONObjBuilder minBuilder;
                BSONObjBuilder maxBuilder;
                BSONForEach(key, keyPattern){
                    minBuilder.appendMinKey( key.fieldName() );
                    maxBuilder.appendMaxKey( key.fieldName() );
                }
开发者ID:ALFIO,项目名称:mongo,代码行数:20,代码来源:d_split.cpp

示例13: allValues

 Interval IndexBoundsBuilder::allValues() {
     BSONObjBuilder bob;
     bob.appendMinKey("");
     bob.appendMaxKey("");
     return makeRangeInterval(bob.obj(), true, true);
 }
开发者ID:ryannutley,项目名称:mongo,代码行数:6,代码来源:index_bounds_builder.cpp

示例14: translate

    // static
    void IndexBoundsBuilder::translate(const MatchExpression* expr, int direction,
                                       OrderedIntervalList* oilOut, bool* exactOut) {
        Interval interval;
        bool exact = false;

        if (expr->isLeaf()) {
            if (MatchExpression::EQ == expr->matchType()) {
                const EqualityMatchExpression* node = static_cast<const EqualityMatchExpression*>(expr);
                // We have to copy the data out of the parse tree and stuff it into the index bounds.
                // BSONValue will be useful here.
                BSONObj dataObj = objFromElement(node->getData());

                if (dataObj.couldBeArray()) {
                    // XXX: build better bounds
                    warning() << "building lazy bounds for " << expr->toString() << endl;
                    interval = allValues();
                    exact = false;
                }
                else {
                    verify(dataObj.isOwned());
                    interval = makePointInterval(dataObj);
                    exact = true;
                }
            }
            else if (MatchExpression::LTE == expr->matchType()) {
                const LTEMatchExpression* node = static_cast<const LTEMatchExpression*>(expr);
                BSONObjBuilder bob;
                bob.appendMinKey("");
                bob.append(node->getData());
                BSONObj dataObj = bob.obj();
                verify(dataObj.isOwned());
                interval = makeRangeInterval(dataObj, true, true);
                exact = true;
            }
            else if (MatchExpression::LT == expr->matchType()) {
                const LTMatchExpression* node = static_cast<const LTMatchExpression*>(expr);
                BSONObjBuilder bob;
                bob.appendMinKey("");
                bob.append(node->getData());
                BSONObj dataObj = bob.obj();
                verify(dataObj.isOwned());
                interval = makeRangeInterval(dataObj, true, false);
                exact = true;
            }
            else if (MatchExpression::GT == expr->matchType()) {
                const GTMatchExpression* node = static_cast<const GTMatchExpression*>(expr);
                BSONObjBuilder bob;
                bob.append(node->getData());
                bob.appendMaxKey("");
                BSONObj dataObj = bob.obj();
                verify(dataObj.isOwned());
                interval = makeRangeInterval(dataObj, false, true);
                exact = true;
            }
            else if (MatchExpression::GTE == expr->matchType()) {
                const GTEMatchExpression* node = static_cast<const GTEMatchExpression*>(expr);
                BSONObjBuilder bob;
                bob.append(node->getData());
                bob.appendMaxKey("");
                BSONObj dataObj = bob.obj();
                verify(dataObj.isOwned());
                interval = makeRangeInterval(dataObj, true, true);
                exact = true;
            }
            else {
                // XXX: build better bounds
                warning() << "building lazy bounds for " << expr->toString() << endl;
                interval = allValues();
                exact = false;
            }
        }
        else {
            // XXX: build better bounds
            verify(expr->isArray());
            warning() << "building lazy bounds for " << expr->toString() << endl;
            interval = allValues();
            exact = false;
        }

        if (-1 == direction) {
            reverseInterval(&interval);
        }

        oilOut->intervals.push_back(interval);
        *exactOut = exact;
    }
开发者ID:idning,项目名称:mongo,代码行数:87,代码来源:index_bounds_builder.cpp

示例15: initial

    // Returns the min and max keys which bound a particular location.
    // The only time these may be equal is when we actually equal the location
    // itself, otherwise our expanding algorithm will fail.
    // static
    bool BtreeLocation::initial(IndexDescriptor* descriptor, const TwoDIndexingParams& params,
            BtreeLocation& min, BtreeLocation& max, GeoHash start) {
        verify(descriptor);

        min._eof = false;
        max._eof = false;

        // Add the range for the 2d indexed field to the keys used.

        // Two scans: one for min one for max.
        IndexScanParams minParams;
        minParams.direction = -1;
        minParams.forceBtreeAccessMethod = true;
        minParams.descriptor = descriptor->clone();
        minParams.bounds.fields.resize(descriptor->keyPattern().nFields());
        minParams.doNotDedup = true;
        // First field of start key goes (MINKEY, start] (in reverse)
        BSONObjBuilder firstBob;
        firstBob.appendMinKey("");
        start.appendToBuilder(&firstBob, "");
        minParams.bounds.fields[0].intervals.push_back(Interval(firstBob.obj(), false, true));

        IndexScanParams maxParams;
        maxParams.forceBtreeAccessMethod = true;
        maxParams.direction = 1;
        maxParams.descriptor = descriptor->clone();
        maxParams.bounds.fields.resize(descriptor->keyPattern().nFields());
        // Don't have the ixscan dedup since we want dup DiskLocs because of multi-point docs.
        maxParams.doNotDedup = true;
        // First field of end key goes (start, MAXKEY)
        BSONObjBuilder secondBob;
        start.appendToBuilder(&secondBob, "");
        secondBob.appendMaxKey("");
        maxParams.bounds.fields[0].intervals.push_back(Interval(secondBob.obj(), false, false));

        BSONObjIterator it(descriptor->keyPattern());
        BSONElement kpElt = it.next();
        maxParams.bounds.fields[0].name = kpElt.fieldName();
        minParams.bounds.fields[0].name = kpElt.fieldName();
        // Fill out the non-2d indexed fields with the "all values" interval, aligned properly.
        size_t idx = 1;
        while (it.more()) {
            kpElt = it.next();
            maxParams.bounds.fields[idx].intervals.push_back(IndexBoundsBuilder::allValues());
            minParams.bounds.fields[idx].intervals.push_back(IndexBoundsBuilder::allValues());
            maxParams.bounds.fields[idx].name = kpElt.fieldName();
            minParams.bounds.fields[idx].name = kpElt.fieldName();
            if (kpElt.number() == -1) {
                IndexBoundsBuilder::reverseInterval(&minParams.bounds.fields[idx].intervals[0]);
                IndexBoundsBuilder::reverseInterval(&maxParams.bounds.fields[idx].intervals[0]);
            }
            ++idx;
        }

        for (size_t i = 0; i < minParams.bounds.fields.size(); ++i) {
            IndexBoundsBuilder::reverseInterval(&minParams.bounds.fields[i].intervals[0]);
        }

        //cout << "keyPattern " << descriptor->keyPattern().toString() << endl;
        //cout << "minBounds " << minParams.bounds.toString() << endl;
        //cout << "maxBounds " << maxParams.bounds.toString() << endl;
        verify(minParams.bounds.isValidFor(descriptor->keyPattern(), -1));
        verify(maxParams.bounds.isValidFor(descriptor->keyPattern(), 1));

        min._ws.reset(new WorkingSet());
        min._scan.reset(new IndexScan(minParams, min._ws.get(), NULL));

        max._ws.reset(new WorkingSet());
        max._scan.reset(new IndexScan(maxParams, max._ws.get(), NULL));

        min.advance();
        max.advance();

        return !max._eof || !min._eof;
    }
开发者ID:Convey-Compliance,项目名称:mongo,代码行数:79,代码来源:2dcommon.cpp


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