[SERVER-6582] findandmodify doesn't set fields properly for getlasterror Created: 24/Jul/12  Updated: 11/Jul/16  Resolved: 01/Aug/12

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.2.0-rc0
Fix Version/s: 2.2.0-rc1

Type: Bug Priority: Major - P3
Reporter: Kristina Chodorow (Inactive) Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

> db.foo.insert({x:1})
> db.foo.findAndModify({query:{x : 1}, update:{$set : {date : new Date()}}})
{ "_id" : ObjectId("500f0966afa3600a3d3fdcd8"), "x" : 1 }
>
> // this should return {"n" : 1, ...
> db.runCommand({getlasterror:1})
{ "n" : 0, "connectionId" : 7, "err" : null, "ok" : 1 }
> db.foo.findOne()
{
        "_id" : ObjectId("500f0966afa3600a3d3fdcd8"),
        "date" : ISODate("2012-07-24T20:45:28.665Z"),
        "x" : 1
}



 Comments   
Comment by Christian Amor Kvalheim [ 01/Aug/12 ]

Is proper write concerns handled like w or is it still only in memory commit?

Comment by auto [ 01/Aug/12 ]

Author:

{u'date': u'2012-07-31T23:27:49-07:00', u'email': u'eliot@10gen.com', u'name': u'Eliot Horowitz'}

Message: SERVER-6582 - find_and_modify - set lastErrorObject fields in some cases like older versions
Branch: master
https://github.com/mongodb/mongo/commit/11559c9bf74be4d4640ba651d98f86909a83bd53

Comment by Kristina Chodorow (Inactive) [ 30/Jul/12 ]

This is a regression.

From Gustavo:

2.2:

> db.runCommand({findAndModify: "test.test", query: {_id: 1}, update: {"$inc": {n: 1}}, upsert: 1})
{ "value" : null, "ok" : 1 }

2.0:

> db.runCommand({findAndModify: "test.test", query: {_id: 1}, update: {"$inc": {n: 1}}, upsert: 1})
{
        "lastErrorObject" : {
                "updatedExisting" : false,
                "n" : 1,
                "connectionId" : 1,
                "err" : null,
                "ok" : 1
        },
        "value" : {
 
        },
        "ok" : 1
}

Generated at Thu Feb 08 03:12:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.