Permalink
Browse files

SERVER-1470 fix upsert with dbref

  • Loading branch information...
1 parent 9ce4fc4 commit f5fa68b120c00b0ccd9dbc95fe18502eb490feba @erh erh committed Jun 2, 2012
Showing with 29 additions and 2 deletions.
  1. +20 −0 jstests/server1470.js
  2. +9 −2 src/mongo/db/ops/update_internal.cpp
View
@@ -0,0 +1,20 @@
+
+t = db.server1470;
+t.drop();
+
+q = { "name" : "first" , "pic" : { "$ref" : "foo", "$id" : ObjectId("4c48d04cd33a5a92628c9af6") } };
+t.update( q , {$set:{ x : 1 } } , true, true );
+ref = t.findOne().pic
+assert.eq( "object", typeof( ref ) );
+assert.eq( q.pic["$ref"] , ref["$ref"] )
+assert.eq( q.pic["$id"] , ref["$id"] )
+
+// just make we haven't broken other update operators
+t.drop();
+t.update( { _id : 1 , x : { $gt : 5 } } , { $set : { y : 1 } } , true );
+assert.eq( { _id : 1 , y : 1 } , t.findOne() );
+
+
+
+
+
@@ -790,8 +790,15 @@ namespace mongo {
continue;
if ( e.type() == Object && e.embeddedObject().firstElementFieldName()[0] == '$' ) {
- // this means this is a $gt type filter, so don't make part of the new object
- continue;
+ // we have something like { x : { $gt : 5 } }
+ // this can be a query piece
+ // or can be a dbref or something
+
+ int op = e.embeddedObject().firstElement().getGtLtOp( -1 );
+ if ( op >= 0 ) {
+ // this means this is a $gt type filter, so don't make part of the new object
+ continue;
+ }
}
eb.appendAs( e , e.fieldName() );

0 comments on commit f5fa68b

Please sign in to comment.