0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/index2.js

41 lines
944 B
JavaScript
Raw Normal View History

2009-01-27 05:28:26 +01:00
/* 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 );
2009-01-31 23:22:22 +01:00
assert(t.validate().valid);