summaryrefslogtreecommitdiff
path: root/jstests/sortc.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sortc.js')
-rw-r--r--jstests/sortc.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/jstests/sortc.js b/jstests/sortc.js
new file mode 100644
index 00000000000..f9aa202508b
--- /dev/null
+++ b/jstests/sortc.js
@@ -0,0 +1,37 @@
+// Test sorting with skipping and multiple candidate query plans.
+
+t = db.jstests_sortc;
+t.drop();
+
+t.save( {a:1} );
+t.save( {a:2} );
+
+function checkA( a, sort, skip, query ) {
+ query = query || {};
+ assert.eq( a, t.find( query ).sort( sort ).skip( skip )[ 0 ].a );
+}
+
+function checkSortAndSkip() {
+ checkA( 1, {a:1}, 0 );
+ checkA( 2, {a:1}, 1 );
+
+ checkA( 1, {a:1}, 0, {a:{$gt:0},b:null} );
+ checkA( 2, {a:1}, 1, {a:{$gt:0},b:null} );
+
+ checkA( 2, {a:-1}, 0 );
+ checkA( 1, {a:-1}, 1 );
+
+ checkA( 2, {a:-1}, 0, {a:{$gt:0},b:null} );
+ checkA( 1, {a:-1}, 1, {a:{$gt:0},b:null} );
+
+ checkA( 1, {$natural:1}, 0 );
+ checkA( 2, {$natural:1}, 1 );
+
+ checkA( 2, {$natural:-1}, 0 );
+ checkA( 1, {$natural:-1}, 1 );
+}
+
+checkSortAndSkip();
+
+t.ensureIndex( {a:1} );
+checkSortAndSkip();