Permalink
Browse files

don't regenerate query in findAndModify unless nessisary

  • Loading branch information...
1 parent 39279bd commit 56f7de6acd4b1a675276a2298bafe9ffdf906d8d @RedBeard0531 RedBeard0531 committed Oct 28, 2010
Showing with 14 additions and 13 deletions.
  1. +14 −13 db/dbcommands.cpp
View
@@ -1359,24 +1359,25 @@ namespace mongo {
} else {
- Query idQuery = QUERY( "_id" << out["_id"]);
-
if (cmdObj["remove"].trueValue()){
uassert(12515, "can't remove and update", cmdObj["update"].eoo());
- db.remove(ns, idQuery, 1);
+ db.remove(ns, QUERY("_id" << out["_id"]), 1);
} else { // update
- // need to include original query for $ positional operator
- BSONObjBuilder b;
- b.append(out["_id"]);
- BSONObjIterator it(origQuery);
- while (it.more()){
- BSONElement e = it.next();
- if (strcmp(e.fieldName(), "_id"))
- b.append(e);
+ if (getGtLtOp(origQuery["_id"]) != BSONObj::Equality){
+ // need to include original query for $ positional operator
+
+ BSONObjBuilder b;
+ b.append(out["_id"]);
+ BSONObjIterator it(origQuery);
+ while (it.more()){
+ BSONElement e = it.next();
+ if (strcmp(e.fieldName(), "_id"))
+ b.append(e);
+ }
+ q = Query(b.obj());
}
- q = Query(b.obj());
BSONElement update = cmdObj["update"];
uassert(12516, "must specify remove or update", !update.eoo());
@@ -1389,7 +1390,7 @@ namespace mongo {
}
if (cmdObj["new"].trueValue())
- out = db.findOne(ns, idQuery, fields);
+ out = db.findOne(ns, QUERY("_id" << out["_id"]), fields);
}
}

0 comments on commit 56f7de6

Please sign in to comment.