mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
34 lines
905 B
JavaScript
34 lines
905 B
JavaScript
|
|
||
|
t = db.embeddedIndexTest;
|
||
|
|
||
|
t.remove( {} );
|
||
|
|
||
|
o = { name : "foo" , z : { a : 17 , b : 4} };
|
||
|
t.save( o );
|
||
|
|
||
|
assert( t.findOne().z.a == 17 );
|
||
|
assert( t.findOne( { z : { a : 17 } } ) == null);
|
||
|
|
||
|
t.ensureIndex( { "z.a" : 1 } );
|
||
|
|
||
|
assert( t.findOne().z.a == 17 );
|
||
|
assert( t.findOne( { z : { a : 17 } } ) == null);
|
||
|
|
||
|
o = { name : "bar" , z : { a : 18 } };
|
||
|
t.save( o );
|
||
|
|
||
|
assert( t.find().length() == 2 );
|
||
|
assert( t.find().sort( { "z.a" : 1 } ).length() == 2 );
|
||
|
assert( t.find().sort( { "z.a" : -1 } ).length() == 2 );
|
||
|
// We are planning to phase out this syntax.
|
||
|
assert( t.find().sort( { z : { a : 1 } } ).length() == 2 );
|
||
|
assert( t.find().sort( { z : { a: -1 } } ).length() == 2 );
|
||
|
|
||
|
//
|
||
|
// TODO - these don't work yet as indexing on x.y doesn't work yet
|
||
|
//
|
||
|
//assert( t.find().sort( { z : { a : 1 } } )[0].name == "foo" );
|
||
|
//assert( t.find().sort( { z : { a : -1 } } )[1].name == "bar" );
|
||
|
|
||
|
assert(t.validate().valid);
|