Browse files

fix upsert for DBRef SERVER-627

  • Loading branch information...
1 parent 7935d23 commit c9ed60974d3a795a25353f3790d6af6093bfad3d @erh erh committed Feb 11, 2010
Showing with 27 additions and 2 deletions.
  1. +0 −1 db/instance.cpp
  2. +4 −1 db/jsobj.cpp
  3. +3 −0 db/update.cpp
  4. +20 −0 jstests/set6.js
View
1 db/instance.cpp
@@ -333,7 +333,6 @@ namespace mongo {
receivedDelete(m, currentOp);
}
else if ( op == dbKillCursors ) {
- mongolock lk(writeLock);
currentOp.ensureStarted();
logThreshold = 10;
ss << "killcursors ";
View
5 db/jsobj.cpp
@@ -1140,7 +1140,10 @@ namespace mongo {
if ( strchr( name , '.' ) ||
strchr( name , '$' ) ){
- return false;
+ return
+ strcmp( name , "$ref" ) == 0 ||
+ strcmp( name , "$id" ) == 0
+ ;
}
if ( e.mayEncapsulate() ){
View
3 db/update.cpp
@@ -633,6 +633,9 @@ namespace mongo {
int profile = cc().database()->profile;
StringBuilder& ss = debug.str;
+ if ( logLevel > 2 )
+ ss << " update: " << updateobj;
+
/* idea with these here it to make them loop invariant for multi updates, and thus be a bit faster for that case */
/* NOTE: when yield() is added herein, these must be refreshed after each call to yield! */
NamespaceDetails *d = nsdetails(ns); // can be null if an upsert...
View
20 jstests/set6.js
@@ -0,0 +1,20 @@
+
+t = db.set6;
+t.drop();
+
+x = { _id : 1 , r : new DBRef( "foo" , new ObjectId() ) }
+t.insert( x )
+assert.eq( x , t.findOne() , "A" );
+
+x.r.$id = new ObjectId()
+t.update({}, { $set : { r : x.r } } );
+assert.eq( x , t.findOne() , "B");
+
+x.r2 = new DBRef( "foo2" , 5 )
+t.update( {} , { $set : { "r2" : x.r2 } } );
+assert.eq( x , t.findOne() , "C" )
+
+x.r.$id = 2;
+t.update( {} , { $set : { "r.$id" : 2 } } )
+assert.eq( x.r.$id , t.findOne().r.$id , "D");
+

0 comments on commit c9ed609

Please sign in to comment.