summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/updatetests.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-07-01 03:56:39 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-07-01 09:04:58 -0400
commitf64357e485c8d46bd6fd393f7416df6117672de1 (patch)
treea90f2bb933dd4a1c2e774ac4e280e8ce7dbcbaeb /src/mongo/dbtests/updatetests.cpp
parente7e24a657b64fa59c30b063c72ff4cbee9674b7e (diff)
downloadmongo-f64357e485c8d46bd6fd393f7416df6117672de1.tar.gz
SERVER-13961 Add OperationContext argument to Client::Context
Time tracking and database access in Client::Context require access to the OperationContext. Adding it as argument. This is in preparation for removing LockState from Client.
Diffstat (limited to 'src/mongo/dbtests/updatetests.cpp')
-rw-r--r--src/mongo/dbtests/updatetests.cpp658
1 files changed, 329 insertions, 329 deletions
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp
index e048ebc2d9f..cbdcc346dc8 100644
--- a/src/mongo/dbtests/updatetests.cpp
+++ b/src/mongo/dbtests/updatetests.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/json.h"
#include "mongo/db/lasterror.h"
#include "mongo/db/ops/update.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
namespace UpdateTests {
@@ -45,27 +46,26 @@ namespace UpdateTests {
class ClientBase {
public:
// NOTE: Not bothering to backup the old error record.
- ClientBase() {
+ ClientBase() : _client(&_txn) {
mongo::lastError.reset( new LastError() );
}
~ClientBase() {
mongo::lastError.release();
}
+
protected:
void insert( const char *ns, BSONObj o ) {
- client_.insert( ns, o );
+ _client.insert( ns, o );
}
void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) {
- client_.update( ns, Query( q ), o, upsert );
+ _client.update( ns, Query( q ), o, upsert );
}
bool error() {
- return !client_.getPrevError().getField( "err" ).isNull();
+ return !_client.getPrevError().getField( "err" ).isNull();
}
- DBDirectClient& client() { return client_; }
-
- private:
- DBDirectClient client_;
+ OperationContextImpl _txn;
+ DBDirectClient _client;
};
class Fail : public ClientBase {
@@ -145,7 +145,7 @@ namespace UpdateTests {
class SetBase : public ClientBase {
public:
~SetBase() {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
protected:
const char *ns() { return "unittests.updatetests.SetBase"; }
@@ -154,45 +154,45 @@ namespace UpdateTests {
class SetNum : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << 1 ) );
- client().update( ns(), BSON( "a" << 1 ), BSON( "$set" << BSON( "a" << 4 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 4 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << 1 ) );
+ _client.update( ns(), BSON( "a" << 1 ), BSON( "$set" << BSON( "a" << 4 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 4 ) ).isEmpty() );
}
};
class SetString : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "b" ) );
- client().update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "c" ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << "c" ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "b" ) );
+ _client.update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "c" ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << "c" ) ).isEmpty() );
}
};
class SetStringDifferentLength : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "b" ) );
- client().update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "cd" ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << "cd" ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "b" ) );
+ _client.update( ns(), BSON( "a" << "b" ), BSON( "$set" << BSON( "a" << "cd" ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << "cd" ) ).isEmpty() );
}
};
class SetStringToNum : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "b" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 5 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 5 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "b" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 5 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 5 ) ).isEmpty() );
}
};
class SetStringToNumInPlace : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << "bcd" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 5.0 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 5.0 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << "bcd" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 5.0 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 5.0 ) ).isEmpty() );
}
};
@@ -200,13 +200,13 @@ namespace UpdateTests {
public:
void run() {
// Try with upsert false first.
- client().insert( ns(), BSONObj() /* empty document */);
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.insert( ns(), BSONObj() /* empty document */);
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
}
};
@@ -215,12 +215,12 @@ namespace UpdateTests {
public:
void run() {
// Try with upsert false first.
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 1 ) ), true );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
}
};
@@ -231,12 +231,12 @@ namespace UpdateTests {
Query q("{a:1}");
// Try with upsert false first.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 << "b" << 1) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "b" << 1 ) ), true );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 << "b" << 1) ).isEmpty() );
}
};
@@ -247,12 +247,12 @@ namespace UpdateTests {
Query q("{a:1}"); // same field that we'll setOnInsert on
// Try with upsert false first.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), false );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 2 ) ).isEmpty() );
+ _client.update( ns(), q, BSON( "$setOnInsert" << BSON( "a" << 2 ) ), true );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 2 ) ).isEmpty() );
}
};
@@ -261,18 +261,18 @@ namespace UpdateTests {
public:
void run() {
BSONObj res = fromjson("{'_id':0, a:1}");
- client().insert( ns(), res );
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "b" << 1 ) ) );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 ) ).woCompare( res ) == 0 );
+ _client.insert( ns(), res );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "b" << 1 ) ) );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 ) ).woCompare( res ) == 0 );
}
};
class SetOnInsertExisting : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 2 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
+ _client.insert( ns(), BSON( "a" << 1 ) );
+ _client.update( ns(), Query(), BSON( "$setOnInsert" << BSON( "a" << 2 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 ) ).isEmpty() );
}
};
@@ -280,14 +280,14 @@ namespace UpdateTests {
public:
void run() {
// Try with upsert false first.
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
"$setOnInsert" << BSON( "b" << 2 ) ), false );
- ASSERT( client().findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
+ ASSERT( _client.findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
// Then with upsert true.
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<
"$setOnInsert" << BSON( "b" << 2 ) ), true );
- ASSERT( !client().findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
+ ASSERT( !_client.findOne( ns(), BSON( "a" << 1 << "b" << 2 ) ).isEmpty() );
}
};
@@ -298,58 +298,58 @@ namespace UpdateTests {
// parent unneccesarily.
BSONObj initial = fromjson( "{'_id':0}" );
BSONObj final = fromjson( "{'_id':0, d:1}" );
- client().insert( ns(), initial );
- client().update( ns(), initial, BSON( "$setOnInsert" << BSON( "a.b" << 1 ) <<
+ _client.insert( ns(), initial );
+ _client.update( ns(), initial, BSON( "$setOnInsert" << BSON( "a.b" << 1 ) <<
"$set" << BSON( "d" << 1 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), initial ), final );
+ ASSERT_EQUALS( _client.findOne( ns(), initial ), final );
}
};
class ModDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$inc" << BSON( "a.b" << 10 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a.b" << 14 ) ).isEmpty() );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 55 ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a.b" << 55 ) ).isEmpty() );
+ _client.insert( ns(), fromjson( "{a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$inc" << BSON( "a.b" << 10 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a.b" << 14 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 55 ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a.b" << 55 ) ).isEmpty() );
}
};
class SetInPlaceDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{a:{b:'cdef'}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "llll" ) ) );
- ASSERT( !client().findOne( ns(), BSON( "a.b" << "llll" ) ).isEmpty() );
+ _client.insert( ns(), fromjson( "{a:{b:'cdef'}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "llll" ) ) );
+ ASSERT( !_client.findOne( ns(), BSON( "a.b" << "llll" ) ).isEmpty() );
}
};
class SetRecreateDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:'cdef'}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
- ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:'cdef'}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
+ ASSERT( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
}
};
class SetMissingDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
- ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
+ ASSERT( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
}
};
class SetAdjacentDotted : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{c:4}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{c:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
ASSERT_EQUALS(
- mutablebson::unordered( client().findOne( ns(), BSON( "a.b" << "lllll" ) ) ),
+ mutablebson::unordered( _client.findOne( ns(), BSON( "a.b" << "lllll" ) ) ),
mutablebson::unordered( fromjson( "{'_id':0,a:{b:'lllll',c:4}}" ) ) );
}
};
@@ -357,9 +357,9 @@ namespace UpdateTests {
class IncMissing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$inc" << BSON( "f" << 3.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,f:3}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$inc" << BSON( "f" << 3.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,f:3}" ) ) == 0 );
}
};
@@ -368,7 +368,7 @@ namespace UpdateTests {
string s() {
stringstream ss;
- auto_ptr<DBClientCursor> cc = client().query( ns() , Query().sort( BSON( "_id" << 1 ) ) );
+ auto_ptr<DBClientCursor> cc = _client.query( ns() , Query().sort( BSON( "_id" << 1 ) ) );
bool first = true;
while ( cc->more() ) {
if ( first ) first = false;
@@ -381,18 +381,18 @@ namespace UpdateTests {
}
void run() {
- client().insert( ns(), BSON( "_id" << 1 << "x" << 1 ) );
- client().insert( ns(), BSON( "_id" << 2 << "x" << 5 ) );
+ _client.insert( ns(), BSON( "_id" << 1 << "x" << 1 ) );
+ _client.insert( ns(), BSON( "_id" << 2 << "x" << 5 ) );
ASSERT_EQUALS( "1,5" , s() );
- client().update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) );
+ _client.update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) );
ASSERT_EQUALS( "2,5" , s() );
- client().update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) );
+ _client.update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) );
ASSERT_EQUALS( "3,5" , s() );
- client().update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true );
+ _client.update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true );
ASSERT_EQUALS( "4,6" , s() );
}
@@ -401,10 +401,10 @@ namespace UpdateTests {
class UnorderedNewSet : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "f.g.h" << 3.0 << "f.g.a" << 2.0 ) ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "f.g.h" << 3.0 << "f.g.a" << 2.0 ) ) );
ASSERT_EQUALS(
- mutablebson::unordered( client().findOne( ns(), Query() ) ),
+ mutablebson::unordered( _client.findOne( ns(), Query() ) ),
mutablebson::unordered( fromjson( "{'_id':0,f:{g:{a:2,h:3}}}" ) ) );
}
};
@@ -412,10 +412,10 @@ namespace UpdateTests {
class UnorderedNewSetAdjacent : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), BSONObj(), BSON( "$set" << BSON( "f.g.h.b" << 3.0 << "f.g.a.b" << 2.0 ) ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "f.g.h.b" << 3.0 << "f.g.a.b" << 2.0 ) ) );
ASSERT_EQUALS(
- mutablebson::unordered( client().findOne( ns(), Query() ) ),
+ mutablebson::unordered( _client.findOne( ns(), Query() ) ),
mutablebson::unordered( fromjson( "{'_id':0,f:{g:{a:{b:2},h:{b:3}}}}" ) ) );
}
};
@@ -423,161 +423,161 @@ namespace UpdateTests {
class ArrayEmbeddedSet : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,z:[4,'b']}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "z.0" << "a" ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,z:['a','b']}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,z:[4,'b']}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "z.0" << "a" ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,z:['a','b']}" ) );
}
};
class AttemptEmbedInExistingNum : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:1}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:1}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
}
};
class AttemptEmbedConflictsWithOtherSet : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0}" ) );
}
};
class ModMasksEmbeddedConflict : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:2}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 2 << "a.b" << 1 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:2}}" ) ) == 0 );
}
};
class ModOverwritesExistingObject : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << BSON( "c" << 2 ) ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{c:2}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:2}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << BSON( "c" << 2 ) ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{c:2}}" ) ) == 0 );
}
};
class InvalidEmbeddedSet : public Fail {
public:
virtual void doIt() {
- client().update( ns(), Query(), BSON( "$set" << BSON( "a." << 1 ) ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a." << 1 ) ) );
}
};
class UpsertMissingEmbedded : public SetBase {
public:
void run() {
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ), true );
- ASSERT( !client().findOne( ns(), QUERY( "a.b" << 1 ) ).isEmpty() );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ), true );
+ ASSERT( !_client.findOne( ns(), QUERY( "a.b" << 1 ) ).isEmpty() );
}
};
class Push : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,5]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,5]}" ) );
}
};
class PushInvalidEltType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:1}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:1}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
}
};
class PushConflictsWithOtherMod : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<"$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[1]}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << 1 ) <<"$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[1]}" ) ) == 0 );
}
};
class PushFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[5]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[5]}" ) );
}
};
class PushFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[5]}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[5]}" ) ) == 0 );
}
};
class PushInsideNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a.b" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:[5]}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a.b" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:[5]}}" ) ) == 0 );
}
};
class CantPushInsideOtherMod : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a" << BSONObj() ) << "$push" << BSON( "a.b" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a" << BSONObj() ) << "$push" << BSON( "a.b" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0}" ) ) == 0 );
}
};
class CantPushTwice : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 4 ) << "$push" << BSON( "a" << 5 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[]}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 4 ) << "$push" << BSON( "a" << 5 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[]}" ) ) == 0 );
}
};
class SetEncapsulationConflictsWithExistingType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b.c" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b.c" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
}
};
class CantPushToParent : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
}
};
class PushEachSimple : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2, 3 ] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 << 3 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
}
};
@@ -585,11 +585,11 @@ namespace UpdateTests {
class PushEachFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
// { $push : { a : { $each : [ 1, 2, 3 ] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
}
};
@@ -597,189 +597,189 @@ namespace UpdateTests {
class PushSliceBelowFull : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2 ] , $slice : -3 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 ) << "$slice" << -3 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
}
};
class PushSliceReachedFullExact : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
}
};
class PushSliceReachedFullWithEach : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
// { $push : { a : { $each : [ 2 , 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 << 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceReachedFullWithBoth : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceToZero : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ] , $slice : 0 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << 0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
}
};
class PushSliceToZeroFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
// { $push : { a : { $each : [ 3 ] , $slice : 0 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) << "$slice" << 0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[]}" ) );
}
};
class PushSliceFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
// { $push : { a : { $each : [ 1 , 2 ] , $slice : -3 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 ) << "$slice" << -3 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2]}" ) );
}
};
class PushSliceLongerThanSliceFromNothing : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
// { $push : { a : { $each : [ 1 , 2 , 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
// { $push : { a : { $each : [ 1 ] , $slice : -3 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 ) << "$slice" << -3 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1]}" ) );
}
};
class PushSliceLongerThanSliceFromEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
// { $push : { a : { $each : [ 1 , 2 , 3 ] , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[2,3]}" ) );
}
};
class PushSliceTwoFields : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3,4]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3,4]}" ) );
// { $push: { a: { $each: [ 5 ] , $slice : -2 }, { b: $each: [ 6 ] , $slice: -1 } } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
BSONObj objB = BSON( "$each" << BSON_ARRAY( 6 ) << "$slice" << -1 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "b" << objB ) ) );
- ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson("{'_id':0,a:[2,5],b:[6]}"));
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "b" << objB ) ) );
+ ASSERT_EQUALS( _client.findOne( ns(), Query() ) , fromjson("{'_id':0,a:[2,5],b:[6]}"));
}
};
class PushSliceAndNormal : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2],b:[3]}" ) );
// { $push : { a : { $each : [ 5 ] , $slice : -2 } , { b : 4 } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON("$push" << BSON("a" << objA << "b" << 4)));
- ASSERT_EQUALS(client().findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,5],b:[3,4]}"));
+ _client.update( ns(), Query(), BSON("$push" << BSON("a" << objA << "b" << 4)));
+ ASSERT_EQUALS(_client.findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,5],b:[3,4]}"));
}
};
class PushSliceTwoFieldsConflict : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
// { $push: { a: { $each: [ 5 ] , $slice: -2 } , { a: $each: [ 6 ] , $slice: -1 } } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
BSONObj other = BSON( "$each" << BSON_ARRAY( 6 ) << "$slice" << -1 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << other ) ) );
- ASSERT(client().findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << other ) ) );
+ ASSERT(_client.findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
}
};
class PushSliceAndNormalConflict : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1],b:[3]}" ) );
// { $push : { a : { $each : [ 5 ] , $slice : -2 } , { a : 4 } } }
BSONObj objA = BSON( "$each" << BSON_ARRAY( 5 ) << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << 4 ) ) );
- ASSERT(client().findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << objA << "a" << 4 ) ) );
+ ASSERT(_client.findOne( ns(), Query()).woCompare(fromjson("{'_id':0,a:[1],b:[3]}"))==0);
}
};
class PushSliceInvalidEachType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : 3 , $slice : -2 } } }
BSONObj pushObj = BSON( "$each" << 3 << "$slice" << -2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne(ns(), Query()).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne(ns(), Query()).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
class PushSliceInvalidSliceType : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : [ -2 ] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << BSON_ARRAY(-2) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
class PushSliceInvalidSliceValue : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : 2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << 2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
@@ -787,33 +787,33 @@ namespace UpdateTests {
class PushSliceInvalidSliceDouble : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : -2.1 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << -2.1 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
class PushSliceValidSliceDouble : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $slice : -2.0 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$slice" << -2.0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT_EQUALS(client().findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,3]}"));
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS(_client.findOne(ns(), Query()) , fromjson("{'_id':0,a:[2,3]}"));
}
};
class PushSliceInvalidSlice : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,a:[1,2]}" ) );
// { $push : { a : { $each : [ 3 ], $xxxx : 2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY(3) << "$xxxx" << 2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare(fromjson("{'_id':0,a:[1,2]}")) == 0);
}
};
@@ -826,7 +826,7 @@ namespace UpdateTests {
class PushSortBase : public ClientBase {
public:
~PushSortBase() {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
protected:
@@ -904,8 +904,8 @@ namespace UpdateTests {
void check( BSONObj expected ) {
std::cout << expected.toString() << std::endl;
- std::cout << client().findOne( ns(), Query() ) << std::endl;
- ASSERT( client().findOne( ns(), Query() ).woCompare( expected ) == 0 );
+ std::cout << _client.findOne( ns(), Query() ) << std::endl;
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( expected ) == 0 );
}
private:
@@ -930,24 +930,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:3, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
BSONObj result;
BSONObj expected;
switch ( i ) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" ) ;
ASSERT_EQUALS( result, expected );
break;
@@ -971,24 +971,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1}]}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1012,22 +1012,22 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
BSONObj result;
BSONObj expected;
switch ( i ) {
case TOPK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1056,14 +1056,14 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:0, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1,b:1},{a:3,b:3}]}" ) );
BSONObj result;
BSONObj expected;
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[]}" );
ASSERT_EQUALS( result, expected );
}
@@ -1085,14 +1085,14 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ {a:2,b:2} ], $slice:0, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
BSONObj result;
BSONObj expected;
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[]}" );
ASSERT_EQUALS( result, expected );
}
@@ -1116,24 +1116,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1158,22 +1158,22 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1203,24 +1203,24 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
case BOTTOMK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:1,b:1},{a:2,b:2}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
case BOTTOMK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1245,22 +1245,22 @@ namespace UpdateTests {
// BOTTOMK_DESC: $push: { x: { $each: [ <genarray> ], $slice:2, $sort: { b:-1 } } }
for ( int i = 0; i < 2; i++ ) { // i < 4 when we have positive $slice
- client().dropCollection( ns() );
- client().insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
+ _client.dropCollection( ns() );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[]}" ) );
BSONObj result;
BSONObj expected;
switch (i) {
case TOPK_ASC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:3,b:3}]}" );
ASSERT_EQUALS( result, expected );
break;
case TOPK_DESC:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), getUpdate(i) );
+ result = _client.findOne( ns(), Query() );
expected = fromjson( "{'_id':0,x:[{a:2,b:2},{a:1,b:1}]}" );
ASSERT_EQUALS( result, expected );
break;
@@ -1416,14 +1416,14 @@ namespace UpdateTests {
// catch bad patterns, we have to write updated that use them.
BSONObj expected = fromjson( "{'_id':0,x:[{a:1}, {a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a..d:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "a..d" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
@@ -1431,32 +1431,32 @@ namespace UpdateTests {
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "a." << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.b:1} } } }
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( ".b" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.:1} } } }
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "." << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {'':1} } } }
pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1465,13 +1465,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ 3 ], $slice:-2, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 3 ) <<
"$slice" << -2 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1480,13 +1480,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : 2} } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << 2 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1495,13 +1495,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:2, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << 2 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1510,13 +1510,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2.1, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2.1 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1524,14 +1524,14 @@ namespace UpdateTests {
class PushSortValidSortDouble : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:2}]}" ) );
// { $push : { x : { $each : [ {a:3} ], $slice:-2.0, $sort : {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2.0 <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
BSONObj expected = fromjson( "{'_id':0,x:[{a:2},{a:3}]}" );
- BSONObj result = client().findOne( ns(), Query() );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1540,13 +1540,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2.0, $sort : [2, 1] } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2.0 <<
"$sort" << BSON_ARRAY( 2 << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1555,13 +1555,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:2}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a:10} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) <<
"$slice" << -2 <<
"$sort" << BSON( "a" << 10 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
};
@@ -1569,14 +1569,14 @@ namespace UpdateTests {
class PushSortInvertedSortAndSlice : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:3}]}" ) );
+ _client.insert( ns(), fromjson( "{'_id':0,x:[{a:1},{a:3}]}" ) );
// { $push : { x : { $each : [ {a:2} ], $sort: {a:1}, $slice:-2 } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 2 ) ) <<
"$sort" << BSON( "a" << 1 ) <<
"$slice" << -2.0 );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
BSONObj expected = fromjson( "{'_id':0,x:[{a:2},{a:3}]}" );
- BSONObj result = client().findOne( ns(), Query() );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
@@ -1586,13 +1586,13 @@ namespace UpdateTests {
public:
void run() {
BSONObj expected = fromjson( "{'_id':0,x:[{a:1},{a:3}]}" );
- client().insert( ns(), expected );
+ _client.insert( ns(), expected );
// { $push : { x : { $each : [ {a:2} ], $sort : {a:1}, $sort: {a:1} } } }
BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 2 ) ) <<
"$sort" << BSON( "a" << 1 ) <<
"$sort" << BSON( "a" << 1 ) );
- client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
- BSONObj result = client().findOne( ns(), Query() );
+ _client.update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) );
+ BSONObj result = _client.findOne( ns(), Query() );
ASSERT_EQUALS( result, expected );
}
@@ -1601,54 +1601,54 @@ namespace UpdateTests {
class CantIncParent : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
- client().update( ns(), Query(), BSON( "$inc" << BSON( "a" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
+ _client.update( ns(), Query(), BSON( "$inc" << BSON( "a" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
}
};
class DontDropEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.c" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{},c:4}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.c" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{},c:4}}" ) ) == 0 );
}
};
class InsertInEmpty : public SetBase {
public:
void run() {
- client().insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
- client().update( ns(), Query(), BSON( "$set" << BSON( "a.b.f" << 4.0 ) ) );
- ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{f:4}}}" ) ) == 0 );
+ _client.insert( ns(), fromjson( "{'_id':0,a:{b:{}}}" ) );
+ _client.update( ns(), Query(), BSON( "$set" << BSON( "a.b.f" << 4.0 ) ) );
+ ASSERT( _client.findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{f:4}}}" ) ) == 0 );
}
};
class IndexParentOfMod : public SetBase {
public:
void run() {
- client().ensureIndex( ns(), BSON( "a" << 1 ) );
- client().insert( ns(), fromjson( "{'_id':0}" ) );
- client().update( ns(), Query(), fromjson( "{$set:{'a.b':4}}" ) );
- ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , client().findOne( ns(), Query() ) );
- ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , client().findOne( ns(), fromjson( "{'a.b':4}" ) ) ); // make sure the index works
+ _client.ensureIndex( ns(), BSON( "a" << 1 ) );
+ _client.insert( ns(), fromjson( "{'_id':0}" ) );
+ _client.update( ns(), Query(), fromjson( "{$set:{'a.b':4}}" ) );
+ ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , _client.findOne( ns(), Query() ) );
+ ASSERT_EQUALS( fromjson( "{'_id':0,a:{b:4}}" ) , _client.findOne( ns(), fromjson( "{'a.b':4}" ) ) ); // make sure the index works
}
};
class PreserveIdWithIndex : public SetBase { // Not using $set, but base class is still useful
public:
void run() {
- client().insert( ns(), BSON( "_id" << 55 << "i" << 5 ) );
- client().update( ns(), BSON( "i" << 5 ), BSON( "i" << 6 ) );
- ASSERT( !client().findOne( ns(), Query( BSON( "_id" << 55 ) ).hint ( "{\"_id\":1}" ) ).isEmpty() );
+ _client.insert( ns(), BSON( "_id" << 55 << "i" << 5 ) );
+ _client.update( ns(), BSON( "i" << 5 ), BSON( "i" << 6 ) );
+ ASSERT( !_client.findOne( ns(), Query( BSON( "_id" << 55 ) ).hint ( "{\"_id\":1}" ) ).isEmpty() );
}
};
class CheckNoMods : public SetBase {
public:
void run() {
- client().update( ns(), BSONObj(), BSON( "i" << 5 << "$set" << BSON( "q" << 3 ) ), true );
+ _client.update( ns(), BSONObj(), BSON( "i" << 5 << "$set" << BSON( "q" << 3 ) ), true );
ASSERT( error() );
}
};
@@ -1656,9 +1656,9 @@ namespace UpdateTests {
class UpdateMissingToNull : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "a" << 5 ) );
- client().update( ns(), BSON( "a" << 5 ), fromjson( "{$set:{b:null}}" ) );
- ASSERT_EQUALS( jstNULL, client().findOne( ns(), QUERY( "a" << 5 ) ).getField( "b" ).type() );
+ _client.insert( ns(), BSON( "a" << 5 ) );
+ _client.update( ns(), BSON( "a" << 5 ), fromjson( "{$set:{b:null}}" ) );
+ ASSERT_EQUALS( jstNULL, _client.findOne( ns(), QUERY( "a" << 5 ) ).getField( "b" ).type() );
}
};
@@ -1666,14 +1666,14 @@ namespace UpdateTests {
class TwoModsWithinDuplicatedField : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "_id" << 0 << "a" << 1
+ _client.insert( ns(), BSON( "_id" << 0 << "a" << 1
<< "x" << BSONObj() << "x" << BSONObj()
<< "z" << 5 ) );
- client().update( ns(), BSONObj(), BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 ) ) );
+ _client.update( ns(), BSONObj(), BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 ) ) );
ASSERT_EQUALS( BSON( "_id" << 0 << "a" << 1
<< "x" << BSON( "b" << 1 << "c" << 1 ) << "x" << BSONObj()
<< "z" << 5 ),
- client().findOne( ns(), BSONObj() ) );
+ _client.findOne( ns(), BSONObj() ) );
}
};
@@ -1681,27 +1681,27 @@ namespace UpdateTests {
class ThreeModsWithinDuplicatedField : public SetBase {
public:
void run() {
- client().insert( ns(),
+ _client.insert( ns(),
BSON( "_id" << 0
<< "x" << BSONObj() << "x" << BSONObj() << "x" << BSONObj() ) );
- client().update( ns(), BSONObj(),
+ _client.update( ns(), BSONObj(),
BSON( "$set" << BSON( "x.b" << 1 << "x.c" << 1 << "x.d" << 1 ) ) );
ASSERT_EQUALS( BSON( "_id" << 0
<< "x" << BSON( "b" << 1 << "c" << 1 << "d" << 1 )
<< "x" << BSONObj() << "x" << BSONObj() ),
- client().findOne( ns(), BSONObj() ) );
+ _client.findOne( ns(), BSONObj() ) );
}
};
class TwoModsBeforeExistingField : public SetBase {
public:
void run() {
- client().insert( ns(), BSON( "_id" << 0 << "x" << 5 ) );
- client().update( ns(), BSONObj(),
+ _client.insert( ns(), BSON( "_id" << 0 << "x" << 5 ) );
+ _client.update( ns(), BSONObj(),
BSON( "$set" << BSON( "a" << 1 << "b" << 1 << "x" << 10 ) ) );
ASSERT_EQUALS(
mutablebson::unordered( BSON( "_id" << 0 << "a" << 1 << "b" << 1 << "x" << 10 ) ),
- mutablebson::unordered( client().findOne( ns(), BSONObj() ) ) );
+ mutablebson::unordered( _client.findOne( ns(), BSONObj() ) ) );
}
};
@@ -1713,15 +1713,15 @@ namespace UpdateTests {
virtual void dotest() = 0;
void insert( const BSONObj& o ) {
- client().insert( ns() , o );
+ _client.insert( ns() , o );
}
void update( const BSONObj& m ) {
- client().update( ns() , BSONObj() , m );
+ _client.update( ns() , BSONObj() , m );
}
BSONObj findOne() {
- return client().findOne( ns() , BSONObj() );
+ return _client.findOne( ns() , BSONObj() );
}
void test( const char* initial , const char* mod , const char* after ) {
@@ -1730,11 +1730,11 @@ namespace UpdateTests {
void test( const BSONObj& initial , const BSONObj& mod , const BSONObj& after ) {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
insert( initial );
update( mod );
ASSERT_EQUALS( after , findOne() );
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
public:
@@ -1744,11 +1744,11 @@ namespace UpdateTests {
}
void run() {
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
dotest();
- client().dropCollection( ns() );
+ _client.dropCollection( ns() );
}
};
@@ -1858,7 +1858,7 @@ namespace UpdateTests {
long long start = numeric_limits<int>::max() - 5;
long long max = numeric_limits<int>::max() + 5ll;
- client().insert( ns() , BSON( "x" << (int)start ) );
+ _client.insert( ns() , BSON( "x" << (int)start ) );
ASSERT( findOne()["x"].type() == NumberInt );
while ( start < max ) {