Permalink
Browse files

make undefined sort same with with and w/o an index SERVER-635

  • Loading branch information...
1 parent 1539083 commit 258fd02642ce228a816634915cce90842ed6d681 @erh erh committed Feb 18, 2010
Showing with 29 additions and 11 deletions.
  1. +1 −1 db/scanandorder.h
  2. +28 −10 jstests/sort6.js
View
@@ -40,7 +40,7 @@ namespace mongo {
// returns the key value for o
BSONObj getKeyFromObject(BSONObj o) {
- return o.extractFields(pattern);
+ return o.extractFields(pattern,true);
}
};
View
@@ -1,20 +1,38 @@
t = db.sort6;
-t.drop();
-
-t.insert({_id:1})
-t.insert({_id:2})
-t.insert({_id:3,c:1})
-t.insert({_id:4,c:2})
function get( x ){
return t.find().sort( { c : x } ).map( function(z){ return z._id; } );
}
-//assert.eq( [4,3,2,1] , get( -1 ) , "A1" )
-assert.eq( [1,2,3,4] , get( 1 ) , "A2" )
+// part 1
+t.drop();
+
+t.insert({_id:1,c:null})
+t.insert({_id:2,c:1})
+t.insert({_id:3,c:2})
+
+
+assert.eq( [3,2,1] , get( -1 ) , "A1" ) // SERVER-635
+assert.eq( [1,2,3] , get( 1 ) , "A2" )
+
+t.ensureIndex( { c : 1 } );
+
+assert.eq( [3,2,1] , get( -1 ) , "B1" )
+assert.eq( [1,2,3] , get( 1 ) , "B2" )
+
+
+// part 2
+t.drop();
+
+t.insert({_id:1})
+t.insert({_id:2,c:1})
+t.insert({_id:3,c:2})
+
+assert.eq( [3,2,1] , get( -1 ) , "C1" ) // SERVER-635
+assert.eq( [1,2,3] , get( 1 ) , "C2" )
t.ensureIndex( { c : 1 } );
-assert.eq( [4,3,2,1] , get( -1 ) , "B1" )
-assert.eq( [1,2,3,4] , get( 1 ) , "B2" )
+assert.eq( [3,2,1] , get( -1 ) , "D1" )
+assert.eq( [1,2,3] , get( 1 ) , "X2" )

0 comments on commit 258fd02

Please sign in to comment.