diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-01-26 23:28:26 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-01-26 23:28:26 -0500 |
commit | bc38646deb39f5d5af3cd33e34f49b596e837401 (patch) | |
tree | 33affd5a1fedb7f8cfad044d92c262d12158ff8b /jstests/cursor5.js | |
parent | f235a0f1b1a8ad6fbbce046205d4b78e60bc1df8 (diff) | |
download | mongo-bc38646deb39f5d5af3cd33e34f49b596e837401.tar.gz |
imported tests
Diffstat (limited to 'jstests/cursor5.js')
-rw-r--r-- | jstests/cursor5.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/jstests/cursor5.js b/jstests/cursor5.js new file mode 100644 index 00000000000..980cf8da735 --- /dev/null +++ b/jstests/cursor5.js @@ -0,0 +1,37 @@ +// 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 ) ); + checkResults( [ z[ 1 ], z[ 3 ] ], r.find( { e: { $gt: 4 }, "a.b": 1 } ).sort( idx ) ); + + checkResults( [ z[ 2 ], z[ 4 ], z[ 0 ] ], r.find( { e: 4 } ).sort( rIdx ) ); + checkResults( [ z[ 3 ], z[ 1 ] ], r.find( { e: { $gt: 4 }, "a.b": 1 } ).sort( rIdx ) ); +} + +db = connect( "test" ); +testBoundsWithSubobjectIndexes( db ); |