Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-6659 - fix find_and_modify when upserting a new doc and origin…

…al query won't work anymore
  • Loading branch information...
commit cbc8b6e716a92357655ff9a33d1c5e1e274744a6 1 parent ba7f067
@erh erh authored
View
7 jstests/find_and_modify_server6659.js
@@ -0,0 +1,7 @@
+
+t = db.find_and_modify_server6659;
+t.drop();
+
+x = t.findAndModify({query:{f:1}, update:{$set:{f:2}}, upsert:true, new:true})
+assert.eq( 2, x.f );
+assert.eq( 2, t.findOne().f );
View
6 src/mongo/db/commands/find_and_modify.cpp
@@ -171,9 +171,13 @@ namespace mongo {
_appendHelper( result , doc , found , fields );
}
- updateObjects( ns.c_str() , update , queryModified , upsert , false , true , cc().curop()->debug() );
+ UpdateResult res = updateObjects( ns.c_str() , update , queryModified , upsert , false , true , cc().curop()->debug() );
if ( returnNew ) {
+ if ( ! res.existing && res.upserted.isSet() ) {
+ queryModified = BSON( "_id" << res.upserted );
+ }
+ log() << "queryModified: " << queryModified << endl;
verify( Helpers::findOne( ns.c_str() , queryModified , doc ) );
_appendHelper( result , doc , true , fields );
}
Please sign in to comment.
Something went wrong with that request. Please try again.