File: or1.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (57 lines) | stat: -rw-r--r-- 1,609 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
t = db.jstests_or1;
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() {

t.save( {_id:0,a:1} );
t.save( {_id:1,a:2} );
t.save( {_id:2,b:1} );
t.save( {_id:3,b:2} );
t.save( {_id:4,a:1,b:1} );
t.save( {_id:5,a:1,b:2} );
t.save( {_id:6,a:2,b:1} );
t.save( {_id:7,a:2,b:2} );

assert.throws( function() { t.find( { $or:"a" } ).toArray(); } );
assert.throws( function() { t.find( { $or:[] } ).toArray(); } );
assert.throws( function() { t.find( { $or:[ "a" ] } ).toArray(); } );

a1 = t.find( { $or: [ { a : 1 } ] } ).toArray();
checkArrs( [ { _id:0, a:1 }, { _id:4, a:1, b:1 }, { _id:5, a:1, b:2 } ], a1 );

a1b2 = t.find( { $or: [ { a : 1 }, { b : 2 } ] } ).toArray();
checkArrs( [ { _id:0, a:1 }, { _id:3, b:2 }, { _id:4, a:1, b:1 }, { _id:5, a:1, b:2 }, { _id:7, a:2, b:2 } ], a1b2 );

t.drop();
t.save( {a:[0,1],b:[0,1]} );
assert.eq( 1, t.find( { $or: [ { a: {$in:[0,1]}}  ] } ).toArray().length );
assert.eq( 1, t.find( { $or: [ { b: {$in:[0,1]}}  ] } ).toArray().length );
assert.eq( 1, t.find( { $or: [ { a: {$in:[0,1]}}, { b: {$in:[0,1]}}  ] } ).toArray().length );

}

doTest();

// not part of SERVER-1003, but good check for subseq. implementations
t.drop();
t.ensureIndex( {a:1} );
doTest();

t.drop();
t.ensureIndex( {b:1} );
doTest();

t.drop();
t.ensureIndex( {a:1,b:1} );
doTest();