File: indexy.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 (35 lines) | stat: -rw-r--r-- 1,586 bytes parent folder | download | duplicates (3)
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
// Null index keys may be generated for documents that do not match null.  In particular, for index
// { 'a.c':1 } the document { a:[ {}, { c:10 } ] } generates index keys { '':null } and { '':10 }.
// While the query { a:{ $elemMatch:{ c:null } } } has been designated to match this document, the
// query { 'a.c':null } has been designated to not match this document.
//
// Because the above and similar queries do not match the document but do match documents lacking
// any 'a.c' field (which also generate a { '':null } key), a Matcher is required when it is
// necessary to select matching documents for these queries.  As a result, the fast count in which
// the matcher is bypassed (SERVER-1752) cannot be used for such queries.  The following tests check
// that the count is calculated correctly in cases where fast count mode should not be applied.
//
// SERVER-4529

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

function assertNoMatch( query ) {
    // Check that no results are returned by a find.
    assert.eq( 0, t.find( query ).itcount() );
    // Check that no results are counted by a count.
    assert.eq( 0, t.find( query ).count() );
}

t.save({a:[{},{c:10}]});
assertNoMatch( { 'a.c':null } );

t.ensureIndex({'a.c':1});
// No equality match against null.
assertNoMatch( { 'a.c':null } );
// No $in match against null.
assertNoMatch( { 'a.c':{ $in:[ null ] } } );
assertNoMatch( { 'a.c':{ $in:[ null, 1 ] } } );
// No match for a query generating the field range [[ minkey, {} ]], which includes the value null,
// on the field 'a.c'.
assertNoMatch( { 'a.c':{ $lt:{} } } );