Permalink
Browse files

fix shell _id moving SERVER-438

  • Loading branch information...
1 parent 0797f88 commit 22f1dc62048250ddc80c156d67368fc623f04300 @erh erh committed Mar 12, 2010
Showing with 14 additions and 12 deletions.
  1. +4 −4 jstests/sort5.js
  2. +10 −8 scripting/engine_spidermonkey.cpp
View
8 jstests/sort5.js
@@ -15,7 +15,7 @@ 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");
+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");
View
18 scripting/engine_spidermonkey.cpp
@@ -193,7 +193,7 @@ namespace mongo {
return oid;
}
- BSONObj toObject( JSObject * o ){
+ BSONObj toObject( JSObject * o , int depth = 0){
if ( ! o )
return BSONObj();
@@ -217,9 +217,11 @@ namespace mongo {
if ( ! appendSpecialDBObject( this , b , "value" , OBJECT_TO_JSVAL( o ) , o ) ){
- jsval theid = getProperty( o , "_id" );
- if ( ! JSVAL_IS_VOID( theid ) ){
- append( b , "_id" , theid );
+ if ( depth == 0 ){
+ jsval theid = getProperty( o , "_id" );
+ if ( ! JSVAL_IS_VOID( theid ) ){
+ append( b , "_id" , theid , EOO , depth + 1 );
+ }
}
JSIdArray * properties = JS_Enumerate( _context , o );
@@ -230,10 +232,10 @@ namespace mongo {
jsval nameval;
assert( JS_IdToValue( _context ,id , &nameval ) );
string name = toString( nameval );
- if ( name == "_id" )
+ if ( depth == 0 && name == "_id" )
continue;
- append( b , name , getProperty( o , name.c_str() ) , orig[name].type() );
+ append( b , name , getProperty( o , name.c_str() ) , orig[name].type() , depth + 1 );
}
JS_DestroyIdArray( _context , properties );
@@ -267,7 +269,7 @@ namespace mongo {
b.appendRegex( name.c_str() , s.substr( 0 , end ).c_str() , s.substr( end + 1 ).c_str() );
}
- void append( BSONObjBuilder& b , string name , jsval val , BSONType oldType = EOO ){
+ void append( BSONObjBuilder& b , string name , jsval val , BSONType oldType = EOO , int depth=0 ){
//cout << "name: " << name << "\t" << typeString( val ) << " oldType: " << oldType << endl;
switch ( JS_TypeOfValue( _context , val ) ){
@@ -291,7 +293,7 @@ namespace mongo {
b.appendNull( name.c_str() );
}
else if ( ! appendSpecialDBObject( this , b , name , val , o ) ){
- BSONObj sub = toObject( o );
+ BSONObj sub = toObject( o , depth );
if ( JS_IsArrayObject( _context , o ) ){
b.appendArray( name.c_str() , sub );
}

0 comments on commit 22f1dc6

Please sign in to comment.