本文整理汇总了C++中BSONObj::woCompare方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::woCompare方法的具体用法?C++ BSONObj::woCompare怎么用?C++ BSONObj::woCompare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObj
的用法示例。
在下文中一共展示了BSONObj::woCompare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: keyBelongsToMe
bool CollectionMetadata::keyBelongsToMe( const BSONObj& key ) const {
// For now, collections don't move. So if the collection is not sharded, assume
// the document with the given key can be accessed.
if ( _keyPattern.isEmpty() ) {
return true;
}
if ( _rangesMap.size() <= 0 ) {
return false;
}
RangeMap::const_iterator it = _rangesMap.upper_bound( key );
if ( it != _rangesMap.begin() ) it--;
bool good = rangeContains( it->first, it->second, key );
#ifdef _DEBUG
// Logs if in debugging mode and the point doesn't belong here.
if ( !good ) {
log() << "bad: " << key << " " << it->first << " " << key.woCompare( it->first ) << " "
<< key.woCompare( it->second ) << endl;
for ( RangeMap::const_iterator i = _rangesMap.begin(); i != _rangesMap.end(); ++i ) {
log() << "\t" << i->first << "\t" << i->second << "\t" << endl;
}
}
#endif
return good;
}
示例2: assertWrittenAsMerged
/**
* Makes sure that all the ranges here no longer exist on disk but the merged range does
*/
void assertWrittenAsMerged(const vector<KeyRange>& ranges) {
dumpServer();
BSONObj rangeMin;
BSONObj rangeMax;
DBDirectClient client(&_txn);
// Ensure written
for (vector<KeyRange>::const_iterator it = ranges.begin(); it != ranges.end(); ++it) {
Query query(BSON(ChunkType::min(it->minKey) << ChunkType::max(it->maxKey)
<< ChunkType::shard(shardName())));
ASSERT(client.findOne(ChunkType::ConfigNS, query).isEmpty());
if (rangeMin.isEmpty() || rangeMin.woCompare(it->minKey) > 0) {
rangeMin = it->minKey;
}
if (rangeMax.isEmpty() || rangeMax.woCompare(it->maxKey) < 0) {
rangeMax = it->maxKey;
}
}
Query query(BSON(ChunkType::min(rangeMin) << ChunkType::max(rangeMax)
<< ChunkType::shard(shardName())));
ASSERT(!client.findOne(ChunkType::ConfigNS, query).isEmpty());
}
示例3: belongsToMe
bool CollectionManager::belongsToMe(const BSONObj& point) const {
// For now, collections don't move. So if the collection is not sharded, assume
// the documet ca be accessed.
if (_key.isEmpty()) {
return true;
}
dassert(_rangesMap.size() > 0);
RangeMap::const_iterator it = _rangesMap.upper_bound(point);
if (it != _rangesMap.begin())
it--;
bool good = contains(it->first, it->second, point);
// Logs if in debugging mode and the point doesn't belong here.
if(dcompare(!good)) {
log() << "bad: " << point << " "
<< it->first << " " << point.woCompare(it->first) << " "
<< point.woCompare(it->second) << endl;
for (RangeMap::const_iterator i=_rangesMap.begin(); i!=_rangesMap.end(); ++i) {
log() << "\t" << i->first << "\t" << i->second << "\t" << endl;
}
}
return good;
}
示例4: assertEquals
static void assertEquals( const BSONObj &a, const BSONObj &b ) {
if ( a.woCompare( b ) != 0 ) {
out() << "expected: " << a.toString()
<< ", got: " << b.toString() << endl;
}
ASSERT( a.woCompare( b ) == 0 );
}
示例5: BSON
TEST( selector, simple_default_test_6 )
{
{
INT32 rc = SDB_OK ;
mthSelector selector ;
BSONObj rule = BSON( "a.b" << BSON( "$default" << 1 ) ) ;
rc = selector.loadPattern( rule ) ;
ASSERT_EQ( SDB_OK , rc ) ;
BSONObj record = BSON( "a" << 1 << "b" << 1) ;
BSONObj result ;
rc = selector.select( record, result ) ;
ASSERT_EQ( SDB_OK , rc ) ;
cout << result.toString( FALSE, TRUE ) << endl ;
BSONObj expect = BSONObj() ;
rc = expect.woCompare( result ) ;
ASSERT_EQ( SDB_OK, rc ) ;
}
{
INT32 rc = SDB_OK ;
mthSelector selector ;
BSONObj rule = BSON( "a.b" << 1 ) ;
rc = selector.loadPattern( rule ) ;
ASSERT_EQ( SDB_OK , rc ) ;
BSONObj record = BSON( "a" << 1 << "b" << 1 ) ;
BSONObj result ;
rc = selector.select( record, result ) ;
ASSERT_EQ( SDB_OK , rc ) ;
cout << result.toString( FALSE, TRUE ) << endl ;
BSONObj expect = BSONObj() ;
rc = expect.woCompare( result ) ;
ASSERT_EQ( SDB_OK, rc ) ;
}
}
示例6: run
void run() {
testRegex();
BSONObjBuilder A,B,C;
A.append("x", 2);
B.append("x", 2.0);
C.append("x", 2.1);
BSONObj a = A.done();
BSONObj b = B.done();
BSONObj c = C.done();
assert( !a.woEqual( b ) ); // comments on operator==
int cmp = a.woCompare(b);
assert( cmp == 0 );
cmp = a.woCompare(c);
assert( cmp < 0 );
testoid();
}
示例7: areResponsesEqual
static bool areResponsesEqual( const BatchedCommandResponse& responseA,
const BatchedCommandResponse& responseB ) {
// TODO: Better reporting of why not equal
if ( responseA.getOk() != responseB.getOk() )
return false;
if ( responseA.getN() != responseB.getN() )
return false;
if ( responseA.isSingleUpsertedSet() != responseB.isSingleUpsertedSet() )
return false;
if ( responseA.isUpsertDetailsSet() != responseB.isUpsertDetailsSet() )
return false;
if ( responseA.isSingleUpsertedSet() ) {
BSONObj upsertA = responseA.getSingleUpserted();
BSONObj upsertB = responseB.getSingleUpserted();
if ( upsertA.woCompare( upsertB ) != 0 )
return false;
}
if ( responseA.isUpsertDetailsSet() ) {
// TODO:
}
if ( responseA.getOk() )
return true;
// TODO: Compare errors here
return true;
}
示例8: compare
int ShardKeyPattern::compare( const BSONObj& lObject , const BSONObj& rObject ) const {
BSONObj L = extractKey(lObject);
uassert( 10198 , "left object doesn't have full shard key", L.nFields() == (int)patternfields.size());
BSONObj R = extractKey(rObject);
uassert( 10199 , "right object doesn't have full shard key", R.nFields() == (int)patternfields.size());
return L.woCompare(R);
}
示例9: testRegex
void testRegex() {
BSONObjBuilder b;
b.appendRegex("x", "foo");
BSONObj o = b.done();
BSONObjBuilder c;
c.appendRegex("x", "goo");
BSONObj p = c.done();
assert( !o.woEqual( p ) );
assert( o.woCompare( p ) < 0 );
{
BSONObjBuilder b;
b.appendRegex("r", "^foo");
BSONObj o = b.done();
assert( o.firstElement().simpleRegex() == "foo" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "^f?oo");
BSONObj o = b.done();
assert( o.firstElement().simpleRegex() == "" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "^fz?oo");
BSONObj o = b.done();
assert( o.firstElement().simpleRegex() == "f" );
}
}
示例10: nss
TEST(QueryRequestTest, ParseFromCommandCommentWithValidMinMax) {
BSONObj cmdObj = fromjson(
"{find: 'testns',"
"comment: 'the comment',"
"min: {a: 1},"
"max: {a: 2}}");
const NamespaceString nss("test.testns");
bool isExplain = false;
unique_ptr<QueryRequest> qr(
assertGet(QueryRequest::makeFromFindCommand(nss, cmdObj, isExplain)));
ASSERT_EQUALS("the comment", qr->getComment());
BSONObj expectedMin = BSON("a" << 1);
ASSERT_EQUALS(0, expectedMin.woCompare(qr->getMin()));
BSONObj expectedMax = BSON("a" << 2);
ASSERT_EQUALS(0, expectedMax.woCompare(qr->getMax()));
}
示例11: ka
TEST(KeyStringTest, Timestamp) {
BSONObj a = BSON("" << Timestamp(0, 0));
BSONObj b = BSON("" << Timestamp(1234, 1));
BSONObj c = BSON("" << Timestamp(1234, 2));
BSONObj d = BSON("" << Timestamp(1235, 1));
{
ROUNDTRIP(a);
ROUNDTRIP(b);
ROUNDTRIP(c);
ASSERT_LESS_THAN(a, b);
ASSERT_LESS_THAN(b, c);
ASSERT_LESS_THAN(c, d);
KeyString ka(a, ALL_ASCENDING);
KeyString kb(b, ALL_ASCENDING);
KeyString kc(c, ALL_ASCENDING);
KeyString kd(d, ALL_ASCENDING);
ASSERT(ka.compare(kb) < 0);
ASSERT(kb.compare(kc) < 0);
ASSERT(kc.compare(kd) < 0);
}
{
Ordering ALL_ASCENDING = Ordering::make(BSON("a" << -1));
ROUNDTRIP(a);
ROUNDTRIP(b);
ROUNDTRIP(c);
ASSERT(d.woCompare(c, ALL_ASCENDING) < 0);
ASSERT(c.woCompare(b, ALL_ASCENDING) < 0);
ASSERT(b.woCompare(a, ALL_ASCENDING) < 0);
KeyString ka(a, ALL_ASCENDING);
KeyString kb(b, ALL_ASCENDING);
KeyString kc(c, ALL_ASCENDING);
KeyString kd(d, ALL_ASCENDING);
ASSERT(ka.compare(kb) > 0);
ASSERT(kb.compare(kc) > 0);
ASSERT(kc.compare(kd) > 0);
}
}
示例12: compare
int ShardKeyPattern::compare( const BSONObj& lObject , const BSONObj& rObject ) const {
BSONObj L = extractKey(lObject);
uassert( 10198 , str::stream() << "left object (" << lObject << ") doesn't have full shard key (" << pattern << ')',
L.nFields() == (int)patternfields.size());
BSONObj R = extractKey(rObject);
uassert( 10199 , str::stream() << "right object (" << rObject << ") doesn't have full shard key (" << pattern << ')',
R.nFields() == (int)patternfields.size());
return L.woCompare(R);
}
示例13:
bool AsyncResultsMerger::MergingComparator::operator()(const size_t& lhs, const size_t& rhs) {
const BSONObj& leftDoc = _remotes[lhs].docBuffer.front();
const BSONObj& rightDoc = _remotes[rhs].docBuffer.front();
BSONObj leftDocKey = leftDoc[ClusterClientCursorParams::kSortKeyField].Obj();
BSONObj rightDocKey = rightDoc[ClusterClientCursorParams::kSortKeyField].Obj();
return leftDocKey.woCompare(rightDocKey, _sort, false /*considerFieldName*/) > 0;
}
示例14: testRegex
void testRegex() {
BSONObjBuilder b;
b.appendRegex("x", "foo");
BSONObj o = b.done();
BSONObjBuilder c;
c.appendRegex("x", "goo");
BSONObj p = c.done();
assert( !o.woEqual( p ) );
assert( o.woCompare( p ) < 0 );
}
示例15: testbounds
void testbounds(){
BSONObj l , r;
{
BSONObjBuilder b;
b.append( "x" , numeric_limits<long long>::max() );
l = b.obj();
}
{
BSONObjBuilder b;
b.append( "x" , numeric_limits<double>::max() );
r = b.obj();
}
assert( l.woCompare( r ) < 0 );
assert( r.woCompare( l ) > 0 );
{
BSONObjBuilder b;
b.append( "x" , numeric_limits<int>::max() );
l = b.obj();
}
assert( l.woCompare( r ) < 0 );
assert( r.woCompare( l ) > 0 );
}