summaryrefslogtreecommitdiff
path: root/jstests/core/or2.js
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2014-02-19 12:45:53 -0500
committerMatt Kangas <matt.kangas@mongodb.com>2014-03-03 22:54:10 -0500
commit3660343e0b4627d2fee4afb89b74d32644d16d18 (patch)
treeffa571e0b73ce56d73c2ae23f458f0db772ef782 /jstests/core/or2.js
parent9fae141a1f3fe652fa6002e47722c5ceb051cffb (diff)
downloadmongo-3660343e0b4627d2fee4afb89b74d32644d16d18.tar.gz
SERVER-12127 migrate js tests to jscore suite when not related to writes
Migrate js tests starting from j-z. Include SERVER-12920 Update use_power_of_2.js Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Diffstat (limited to 'jstests/core/or2.js')
-rw-r--r--jstests/core/or2.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/jstests/core/or2.js b/jstests/core/or2.js
new file mode 100644
index 00000000000..00e9f68decf
--- /dev/null
+++ b/jstests/core/or2.js
@@ -0,0 +1,69 @@
+t = db.jstests_or2;
+t.drop();
+
+checkArrs = function( a, b, m ) {
+ assert.eq( a.length, b.length, m );
+ aStr = [];
+ bStr = [];
+ a.forEach( function( x ) { aStr.push( tojson( x ) ); } );
+ b.forEach( function( x ) { bStr.push( tojson( x ) ); } );
+ for ( i = 0; i < aStr.length; ++i ) {
+ assert( -1 != bStr.indexOf( aStr[ i ] ), m );
+ }
+}
+
+doTest = function( index ) {
+ if ( index == null ) {
+ index = true;
+ }
+
+ t.save( {_id:0,x:0,a:1} );
+ t.save( {_id:1,x:0,a:2} );
+ t.save( {_id:2,x:0,b:1} );
+ t.save( {_id:3,x:0,b:2} );
+ t.save( {_id:4,x:1,a:1,b:1} );
+ t.save( {_id:5,x:1,a:1,b:2} );
+ t.save( {_id:6,x:1,a:2,b:1} );
+ t.save( {_id:7,x:1,a:2,b:2} );
+
+ assert.throws( function() { t.find( { x:0,$or:"a" } ).toArray(); } );
+ assert.throws( function() { t.find( { x:0,$or:[] } ).toArray(); } );
+ assert.throws( function() { t.find( { x:0,$or:[ "a" ] } ).toArray(); } );
+
+ a1 = t.find( { x:0, $or: [ { a : 1 } ] } ).toArray();
+ checkArrs( [ { _id:0, x:0, a:1 } ], a1 );
+ if ( index ) {
+ assert( t.find( { x:0,$or: [ { a : 1 } ] } ).explain().cursor.match( /Btree/ ) );
+ }
+
+ a1b2 = t.find( { x:1, $or: [ { a : 1 }, { b : 2 } ] } ).toArray();
+ checkArrs( [ { _id:4, x:1, a:1, b:1 }, { _id:5, x:1, a:1, b:2 }, { _id:7, x:1, a:2, b:2 } ], a1b2 );
+ if ( index ) {
+ assert( t.find( { x:0,$or: [ { a : 1 } ] } ).explain().cursor.match( /Btree/ ) );
+ }
+
+ /*
+ t.drop();
+ obj = {_id:0,x:10,a:[1,2,3]};
+ t.save( obj );
+ t.update( {x:10,$or:[ {a:2} ]}, {$set:{'a.$':100}} );
+ assert.eq( obj, t.findOne() ); // no change
+ */
+}
+
+doTest( false );
+
+t.ensureIndex( { x:1 } );
+doTest();
+
+t.drop();
+t.ensureIndex( { x:1,a:1 } );
+doTest();
+
+t.drop();
+t.ensureIndex( {x:1,b:1} );
+doTest();
+
+t.drop();
+t.ensureIndex( {x:1,a:1,b:1} );
+doTest();