blob: b54abcaa792f8a02eefb23b5955dd9b8fc372704 (
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
37
38
39
40
|
/* 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);
|