Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix findAndModify when sort is used and _id in query SERVER-2530

  • Loading branch information...
commit 3d8ca912a03cb6e6a0ebc431ac72c3b89e87b7be 1 parent 9b5be3e
@RedBeard0531 RedBeard0531 authored
Showing with 5 additions and 2 deletions.
  1. +3 −0  db/dbcommands.cpp
  2. +2 −2 jstests/find_and_modify3.js
View
3  db/dbcommands.cpp
@@ -1473,6 +1473,9 @@ namespace mongo {
q = Query(b.obj());
}
+ if (q.isComplex()) // update doesn't work with complex queries
+ q = Query(q.getFilter().getOwned());
+
BSONElement update = cmdObj["update"];
uassert(12516, "must specify remove or update", !update.eoo());
db.update(ns, q, update.embeddedObjectUserCheck());
View
4 jstests/find_and_modify3.js
@@ -8,13 +8,13 @@ t.insert({_id:2, other:2, comments:[{i:0, j:0}, {i:1, j:1}]});
orig0 = t.findOne({_id:0})
orig2 = t.findOne({_id:2})
-out = t.findAndModify({query: {_id:1, 'comments.i':0}, update: {$set: {'comments.$.j':2}}, 'new': true});
+out = t.findAndModify({query: {_id:1, 'comments.i':0}, update: {$set: {'comments.$.j':2}}, 'new': true, sort:{other:1}});
assert.eq(out.comments[0], {i:0, j:2});
assert.eq(out.comments[1], {i:1, j:1});
assert.eq(t.findOne({_id:0}), orig0);
assert.eq(t.findOne({_id:2}), orig2);
-out = t.findAndModify({query: {other:1, 'comments.i':1}, update: {$set: {'comments.$.j':3}}, 'new': true});
+out = t.findAndModify({query: {other:1, 'comments.i':1}, update: {$set: {'comments.$.j':3}}, 'new': true, sort:{other:1}});
assert.eq(out.comments[0], {i:0, j:2});
assert.eq(out.comments[1], {i:1, j:3});
assert.eq(t.findOne({_id:0}), orig0);
Please sign in to comment.
Something went wrong with that request. Please try again.