summaryrefslogtreecommitdiff
path: root/jstests/cursor5.js
blob: 6434d2b38874c7124b3ff9a2c4d32e793522a466 (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
// Test bounds with subobject indexes.

function checkResults( expected, cursor ) {
    assert.eq( expected.length, cursor.count() );
    for( i = 0; i < expected.length; ++i ) {
	assert.eq( expected[ i ].a.b, cursor[ i ].a.b );
	assert.eq( expected[ i ].a.c, cursor[ i ].a.c );
	assert.eq( expected[ i ].a.d, cursor[ i ].a.d );
	assert.eq( expected[ i ].e, cursor[ i ].e );
    }
}

function testBoundsWithSubobjectIndexes( db ) {
    r = db.ed_db_cursor5_bwsi;
    r.drop();

    z = [ { a: { b: 1, c: 2, d: 3 }, e: 4 },
	  { a: { b: 1, c: 2, d: 3 }, e: 5 },
	  { a: { b: 1, c: 2, d: 4 }, e: 4 },
	  { a: { b: 1, c: 2, d: 4 }, e: 5 },
	  { a: { b: 2, c: 2, d: 3 }, e: 4 },
	  { a: { b: 2, c: 2, d: 3 }, e: 5 } ];
    for( i = 0; i < z.length; ++i )
	r.save( z[ i ] );
    idx = { "a.d": 1, a: 1, e: -1 };
    rIdx = { "a.d": -1, a: -1, e: 1 };
    r.ensureIndex( idx );

    checkResults( [ z[ 0 ], z[ 4 ], z[ 2 ] ], r.find( { e: 4 } ).sort( idx ).hint( idx ) );
    checkResults( [ z[ 1 ], z[ 3 ] ], r.find( { e: { $gt: 4 }, "a.b": 1 } ).sort( idx ).hint( idx ) );

    checkResults( [ z[ 2 ], z[ 4 ], z[ 0 ] ], r.find( { e: 4 } ).sort( rIdx ).hint( idx ) );
    checkResults( [ z[ 3 ], z[ 1 ] ], r.find( { e: { $gt: 4 }, "a.b": 1 } ).sort( rIdx ).hint( idx ) );
}

testBoundsWithSubobjectIndexes( db );