File: and3.js

package info (click to toggle)
mongodb 1%3A2.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,204 kB
  • sloc: cpp: 109,783; ansic: 101,073; python: 2,287; perl: 395; makefile: 370; sh: 242; asm: 46
file content (66 lines) | stat: -rw-r--r-- 2,505 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
58
59
60
61
62
63
64
65
66
// Check key match with sub matchers - part of SERVER-3192

t = db.jstests_and3;
t.drop();

t.save( {a:1} );
t.save( {a:'foo'} );

t.ensureIndex( {a:1} );

function checkScanMatch( query, nscannedObjects, n ) {
 	var e = t.find( query ).hint( {a:1} ).explain();
    // NOTE The nscannedObjects values aren't necessarily optimal currently,
    // we're just checking current behavior here.
    assert.eq( nscannedObjects, e.nscannedObjects );
    assert.eq( n, e.n );
}

checkScanMatch( {a:/o/}, 1, 1 );
checkScanMatch( {a:/a/}, 0, 0 );
checkScanMatch( {a:{$not:/o/}}, 2, 1 );
checkScanMatch( {a:{$not:/a/}}, 2, 2 );

checkScanMatch( {$and:[{a:/o/}]}, 1, 1 );
checkScanMatch( {$and:[{a:/a/}]}, 0, 0 );
checkScanMatch( {$and:[{a:{$not:/o/}}]}, 2, 1 );
checkScanMatch( {$and:[{a:{$not:/a/}}]}, 2, 2 );
checkScanMatch( {$and:[{a:/o/},{a:{$not:/o/}}]}, 1, 0 );
checkScanMatch( {$and:[{a:/o/},{a:{$not:/a/}}]}, 1, 1 );
checkScanMatch( {$or:[{a:/o/}]}, 1, 1 );
checkScanMatch( {$or:[{a:/a/}]}, 0, 0 );
checkScanMatch( {$nor:[{a:/o/}]}, 2, 1 );
checkScanMatch( {$nor:[{a:/a/}]}, 2, 2 );

checkScanMatch( {$and:[{$and:[{a:/o/}]}]}, 1, 1 );
checkScanMatch( {$and:[{$and:[{a:/a/}]}]}, 0, 0 );
checkScanMatch( {$and:[{$and:[{a:{$not:/o/}}]}]}, 2, 1 );
checkScanMatch( {$and:[{$and:[{a:{$not:/a/}}]}]}, 2, 2 );
checkScanMatch( {$and:[{$or:[{a:/o/}]}]}, 1, 1 );
checkScanMatch( {$and:[{$or:[{a:/a/}]}]}, 0, 0 );
checkScanMatch( {$or:[{a:{$not:/o/}}]}, 2, 1 );
checkScanMatch( {$and:[{$or:[{a:{$not:/o/}}]}]}, 2, 1 );
checkScanMatch( {$and:[{$or:[{a:{$not:/a/}}]}]}, 2, 2 );
checkScanMatch( {$and:[{$nor:[{a:/o/}]}]}, 2, 1 );
checkScanMatch( {$and:[{$nor:[{a:/a/}]}]}, 2, 2 );

checkScanMatch( {$where:'this.a==1'}, 2, 1 );
checkScanMatch( {$and:[{$where:'this.a==1'}]}, 2, 1 );

checkScanMatch( {a:1,$where:'this.a==1'}, 1, 1 );
checkScanMatch( {a:1,$and:[{$where:'this.a==1'}]}, 1, 1 );
checkScanMatch( {$and:[{a:1},{$where:'this.a==1'}]}, 1, 1 );
checkScanMatch( {$and:[{a:1,$where:'this.a==1'}]}, 1, 1 );
checkScanMatch( {a:1,$and:[{a:1},{a:1,$where:'this.a==1'}]}, 1, 1 );

function checkImpossibleMatch( query ) {
    var e = t.find( query ).explain();
    assert.eq( 0, e.n );
    assert.eq( 'BasicCursor', e.cursor );
}

// With a single key index, all bounds are utilized.
assert.eq( [[1,1]], t.find( {$and:[{a:1}]} ).explain().indexBounds.a );
assert.eq( [[1,1]], t.find( {a:1,$and:[{a:1}]} ).explain().indexBounds.a );
checkImpossibleMatch( {a:1,$and:[{a:2}]} );
checkImpossibleMatch( {$and:[{a:1},{a:2}]} );