summaryrefslogtreecommitdiff
path: root/jstests/core/null2.js
blob: 17b1a39271443875150c8339e28fb6fb89683af2 (plain)
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

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

t.insert( { _id : 1, a : [ { b : 5 } ] } );
t.insert( { _id : 2, a : [ {} ] } );
t.insert( { _id : 3, a : [] } );
t.insert( { _id : 4, a : [ {}, { b : 5 } ] } );
t.insert( { _id : 5, a : [ 5, { b : 5 } ] } );

function doQuery( query ) {
    printjson( query );
    t.find( query ).forEach(
        function(z) {
            print( "\t" + tojson(z) );
        }
    );
    return t.find( query ).count();
}

function getIds( query ) {
    var ids = []
    t.find( query ).forEach(
        function(z) {
            ids.push( z._id );
        }
    );
    return ids;
}

theQueries = [ { "a.b" : null }, { "a.b" : { $in : [ null ] } } ];

for ( var i=0; i < theQueries.length; i++ ) {
    assert.eq( 2, doQuery( theQueries[i] ) );
    assert.eq( [2,4], getIds( theQueries[i] ) );
}

t.ensureIndex( { "a.b" : 1 } )

for ( var i=0; i < theQueries.length; i++ ) {
    assert.eq( 2, doQuery( theQueries[i] ) );
    assert.eq( [2,4], getIds( theQueries[i] ) );
}