diff options
author | Antonin Kral <a.kral@bobek.cz> | 2010-08-11 12:38:57 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2010-08-11 12:38:57 +0200 |
commit | 7645618fd3914cb8a20561625913c20d49504a49 (patch) | |
tree | 8370f846f58f6d71165b7a0e2eda04648584ec76 /jstests/or2.js | |
parent | 68c73c3c7608b4c87f07440dc3232801720b1168 (diff) | |
download | mongodb-7645618fd3914cb8a20561625913c20d49504a49.tar.gz |
Imported Upstream version 1.6.0
Diffstat (limited to 'jstests/or2.js')
-rw-r--r-- | jstests/or2.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/jstests/or2.js b/jstests/or2.js new file mode 100644 index 0000000..d90cc85 --- /dev/null +++ b/jstests/or2.js @@ -0,0 +1,68 @@ +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 in aStr ) { + 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(); } ); + assert.throws( function() { t.find( { x:0,$or:[ {x:0,$or:[{x:0}]} ] } ).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(); |