summaryrefslogtreecommitdiff
path: root/jstests/index1.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/index1.js')
-rw-r--r--jstests/index1.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/index1.js b/jstests/index1.js
new file mode 100644
index 0000000..620f8bb
--- /dev/null
+++ b/jstests/index1.js
@@ -0,0 +1,33 @@
+
+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);