0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00
mongodb/jstests/index2.js
2009-01-31 17:22:22 -05:00

41 lines
944 B
JavaScript

/* test indexing where the key is an embedded object.
*/
t = db.embeddedIndexTest2;
t.drop();
assert( t.findOne() == null );
o = { name : "foo" , z : { a : 17 } };
p = { name : "foo" , z : { a : 17 } };
q = { name : "barrr" , z : { a : 18 } };
r = { name : "barrr" , z : { k : "zzz", L:[1,2] } };
t.save( o );
assert( t.findOne().z.a == 17 );
t.save( p );
t.save( q );
assert( t.findOne({z:{a:17}}).z.a==17 );
assert( t.find({z:{a:17}}).length() == 2 );
assert( t.find({z:{a:18}}).length() == 1 );
t.save( r );
assert( t.findOne({z:{a:17}}).z.a==17 );
assert( t.find({z:{a:17}}).length() == 2 );
assert( t.find({z:{a:18}}).length() == 1 );
t.ensureIndex( { z : 1 } );
assert( t.findOne({z:{a:17}}).z.a==17 );
assert( t.find({z:{a:17}}).length() == 2 );
assert( t.find({z:{a:18}}).length() == 1 );
assert( t.find().sort( { z : 1 } ).length() == 4 );
assert( t.find().sort( { z : -1 } ).length() == 4 );
assert(t.validate().valid);