summaryrefslogtreecommitdiff
path: root/jstests/sort5.js
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2010-01-31 08:32:52 +0100
committerAntonin Kral <a.kral@bobek.cz>2010-01-31 08:32:52 +0100
commit4eefaf421bfeddf040d96a3dafb12e09673423d7 (patch)
treecb2e5ccc7f98158894f977ff131949da36673591 /jstests/sort5.js
downloadmongodb-4eefaf421bfeddf040d96a3dafb12e09673423d7.tar.gz
Imported Upstream version 1.3.1
Diffstat (limited to 'jstests/sort5.js')
-rw-r--r--jstests/sort5.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/jstests/sort5.js b/jstests/sort5.js
new file mode 100644
index 0000000..a589355
--- /dev/null
+++ b/jstests/sort5.js
@@ -0,0 +1,21 @@
+var t = db.sort5;
+t.drop();
+
+t.save({_id: 5, x: 1, y: {a: 5, b: 4}});
+t.save({_id: 7, x: 2, y: {a: 7, b: 3}});
+t.save({_id: 2, x: 3, y: {a: 2, b: 3}});
+t.save({_id: 9, x: 4, y: {a: 9, b: 3}});
+
+// test compound sorting
+
+assert.eq( [4,2,3,1] , t.find().sort({"y.b": 1 , "y.a" : -1 }).map( function(z){ return z.x; } ) , "A no index" );
+t.ensureIndex({"y.b": 1, "y.a": -1});
+assert.eq( [4,2,3,1] , t.find().sort({"y.b": 1 , "y.a" : -1 }).map( function(z){ return z.x; } ) , "A index" );
+assert(t.validate().valid, "A valid");
+
+// test sorting on compound key involving _id
+
+// assert.eq( [4,2,3,1] , t.find().sort({"y.b": 1 , _id : -1 }).map( function(z){ return z.x; } ) , "B no index" );
+// t.ensureIndex({"y.b": 1, "_id": -1});
+// assert.eq( [4,2,3,1] , t.find().sort({"y.b": 1 , _id : -1 }).map( function(z){ return z.x; } ) , "B index" );
+// assert(t.validate().valid, "B valid");