From 3247006c76379d26f490727fbea723a3583ba039 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Thu, 14 May 2009 16:35:43 -0400 Subject: [PATCH] more tests passing, _id in front --- jstests/count.js | 20 ++++++++++---------- jstests/objid1.js | 10 +++++----- jstests/objid3.js | 2 +- scripting/engine_spidermonkey.cpp | 7 +++++++ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/jstests/count.js b/jstests/count.js index 129a369f973d3..5d83502a717f0 100644 --- a/jstests/count.js +++ b/jstests/count.js @@ -3,21 +3,21 @@ t = db.jstests_count; t.drop(); t.save( { i: 1 } ); t.save( { i: 2 } ); -assert.eq( 1, t.find( { i: 1 } ).count() ); -assert.eq( 1, t.count( { i: 1 } ) ); -assert.eq( 2, t.find().count() ); -assert.eq( 2, t.find( undefined ).count() ); -assert.eq( 2, t.find( null ).count() ); -assert.eq( 2, t.count() ); +assert.eq( 1, t.find( { i: 1 } ).count(), "A" ); +assert.eq( 1, t.count( { i: 1 } ) , "B" ); +assert.eq( 2, t.find().count() , "C" ); +assert.eq( 2, t.find( undefined ).count() , "D" ); +assert.eq( 2, t.find( null ).count() , "E" ); +assert.eq( 2, t.count() , "F" ); t.drop(); t.save( {a:true,b:false} ); t.ensureIndex( {b:1,a:1} ); -assert.eq( 1, t.find( {a:true,b:false} ).count() ); -assert.eq( 1, t.find( {b:false,a:true} ).count() ); +assert.eq( 1, t.find( {a:true,b:false} ).count() , "G" ); +assert.eq( 1, t.find( {b:false,a:true} ).count() , "H" ); t.drop(); t.save( {a:true,b:false} ); t.ensureIndex( {b:1,a:1,c:1} ); -assert.eq( 1, t.find( {a:true,b:false} ).count() ); -assert.eq( 1, t.find( {b:false,a:true} ).count() ); +assert.eq( 1, t.find( {a:true,b:false} ).count() , "I" ); +assert.eq( 1, t.find( {b:false,a:true} ).count() , "J" ); diff --git a/jstests/objid1.js b/jstests/objid1.js index 99a7aeb1a6fb1..f0b62ef5d0c12 100644 --- a/jstests/objid1.js +++ b/jstests/objid1.js @@ -2,12 +2,12 @@ t = db.objid1; t.drop(); b = new ObjectId(); -assert( b.str , "objid1 test1" ); +assert( b.str , "A" ); -a = ObjectId( b.str ); -assert.eq( a.str , b.str ); +a = new ObjectId( b.str ); +assert.eq( a.str , b.str , "B" ); t.save( { a : a } ) -assert( t.findOne().a.isObjectId ); -assert.eq( a.str , t.findOne().a.str ); +assert( t.findOne().a.isObjectId , "C" ); +assert.eq( a.str , t.findOne().a.str , "D" ); diff --git a/jstests/objid3.js b/jstests/objid3.js index 02702e60b5c92..ddf20d9af27c8 100644 --- a/jstests/objid3.js +++ b/jstests/objid3.js @@ -3,7 +3,7 @@ t.drop(); t.save( { a : "bob" , _id : 517 } ); for ( var k in t.findOne() ){ - assert.eq( k , "_id" ); + assert.eq( k , "_id" , "keys out of order" ); break; } diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 73af3c5968784..4927f6cd4582c 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -109,6 +109,11 @@ namespace mongo { BSONObjBuilder b; + jsval theid = getProperty( o , "_id" ); + if ( ! JSVAL_IS_VOID( theid ) ){ + append( b , "_id" , theid ); + } + JSIdArray * properties = JS_Enumerate( _context , o ); assert( properties ); @@ -117,6 +122,8 @@ namespace mongo { jsval nameval; assert( JS_IdToValue( _context ,id , &nameval ) ); string name = toString( nameval ); + if ( name == "_id" ) + continue; append( b , name , getProperty( o , name.c_str() ) ); }