Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-3192 a few more test cases

  • Loading branch information...
commit 666397744ecbcfd1237ffe1dd454e1502ab3f60b 1 parent 6646b90
@astaple astaple authored
Showing with 46 additions and 2 deletions.
  1. +46 −2 jstests/orj.js
View
48 jstests/orj.js
@@ -3,6 +3,8 @@
t = db.jstests_orj;
t.drop();
+t.save( {a:1,b:2} );
+
function check() {
assert.throws( function() { t.find( { x:0,$or:"a" } ).toArray(); } );
@@ -21,8 +23,6 @@ assert.throws( function() { t.find( { x:0,$nor:[{$nor:"a"}] } ).toArray(); } );
assert.throws( function() { t.find( { x:0,$nor:[{$nor:[]}] } ).toArray(); } );
assert.throws( function() { t.find( { x:0,$nor:[{$nor:[ "a" ]}] } ).toArray(); } );
-t.remove();
-t.save( {a:1,b:2} );
assert.eq( 1, t.find( {a:1,b:2} ).itcount() );
assert.eq( 1, t.find( {a:1,$or:[{b:2}]} ).itcount() );
@@ -75,3 +75,47 @@ t.dropIndexes();
t.ensureIndex( {a:1,b:1} );
check();
t.dropIndexes();
+
+t.ensureIndex( {a:1} );
+t.ensureIndex( {b:1} );
+t.ensureIndex( {a:1,b:1} );
+check();
+
+function checkHinted( hint ) {
+ assert.eq( 1, t.find( {a:1,b:2} ).hint( hint ).itcount() );
+
+ assert.eq( 1, t.find( {a:1,$or:[{b:2}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {a:1,$or:[{b:3}]} ).hint( hint ).itcount() );
+
+ assert.eq( 1, t.find( {a:1,$or:[{$or:[{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 1, t.find( {a:1,$or:[{$or:[{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {a:1,$or:[{$or:[{b:3}]}]} ).hint( hint ).itcount() );
+
+ assert.eq( 1, t.find( {$or:[{$or:[{a:2},{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 1, t.find( {$or:[{a:2},{$or:[{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 1, t.find( {$or:[{a:1},{$or:[{b:3}]}]} ).hint( hint ).itcount() );
+
+ assert.eq( 1, t.find( {$or:[{$or:[{a:1},{a:2}]},{$or:[{b:3},{b:4}]}]} ).hint( hint ).itcount() );
+ assert.eq( 1, t.find( {$or:[{$or:[{a:0},{a:2}]},{$or:[{b:2},{b:4}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {$or:[{$or:[{a:0},{a:2}]},{$or:[{b:3},{b:4}]}]} ).hint( hint ).itcount() );
+
+ assert.eq( 1, t.find( {a:1,$and:[{$or:[{$or:[{b:2}]}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {a:1,$and:[{$or:[{$or:[{b:3}]}]}]} ).hint( hint ).itcount() );
+
+ assert.eq( 1, t.find( {$and:[{$or:[{a:1},{a:2}]},{$or:[{b:1},{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {$and:[{$or:[{a:3},{a:2}]},{$or:[{b:1},{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {$and:[{$or:[{a:1},{a:2}]},{$or:[{b:3},{b:1}]}]} ).hint( hint ).itcount() );
+
+ assert.eq( 0, t.find( {$and:[{$nor:[{a:1},{a:2}]},{$nor:[{b:1},{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {$and:[{$nor:[{a:3},{a:2}]},{$nor:[{b:1},{b:2}]}]} ).hint( hint ).itcount() );
+ assert.eq( 1, t.find( {$and:[{$nor:[{a:3},{a:2}]},{$nor:[{b:3},{b:1}]}]} ).hint( hint ).itcount() );
+
+ assert.eq( 1, t.find( {$and:[{$or:[{a:1},{a:2}]},{$nor:[{b:1},{b:3}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {$and:[{$or:[{a:3},{a:2}]},{$nor:[{b:1},{b:3}]}]} ).hint( hint ).itcount() );
+ assert.eq( 0, t.find( {$and:[{$or:[{a:1},{a:2}]},{$nor:[{b:1},{b:2}]}]} ).hint( hint ).itcount() );
+}
+
+checkHinted( {$natural:1} );
+checkHinted( {a:1} );
+checkHinted( {b:1} );
+checkHinted( {a:1,b:1} );
Please sign in to comment.
Something went wrong with that request. Please try again.