[SERVER-8422] Log/getLastError/profile output reports nupdated:1 even if no change Created: 31/Jan/13  Updated: 10/Dec/14  Resolved: 04/Mar/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: daniel.roberts@10gen.com Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: getLastError, modifiers, updates
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3409 WriteResult should indicate number of... Closed
Related
related to SERVER-6399 Refactor update() code Closed
Operating System: ALL
Participants:

 Description   

Repro:

> db.d.insert({_id:1})
> db.d.update({}, {$unset:{fake:1}});db.getLastErrorObj()
{
	"updatedExisting" : true,
	"n" : 1,
	"lastOp" : {
		"t" : 1360957938000,
		"i" : 1
	},
	"connectionId" : 86,
	"err" : null,
	"ok" : 1
}
> db.d.find()
{_id:1}



 Comments   
Comment by Daniel Pasette (Inactive) [ 04/Mar/14 ]

fixed in SERVER-3409.

Update commands now return nMatched, nUpserted and nModified as distinct return fields.

> db.d.update({}, {$set:{fake:1}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })

Comment by Scott Hernandez (Inactive) [ 20/Feb/13 ]

What does nupdated mean if not the number of updated docs based on the update operation?

Currently many clients expose and use "n" in the WriteResult (GLE response) as an indication of the number of affected documents.

Perhaps we should add "nfound" to indicate the query matches and n/nupdated to indicate the modified/updated docs for backwards compatibility and based on current user understandings.

From the user point of view, what is the difference of "updated" and "modified"? When do you ever update a document where you did not modify it?

Comment by Eliot Horowitz (Inactive) [ 20/Feb/13 ]

"n" should be the number of documents matched
there should be another field for tracking actual changes
probably not updated, but this would be a new "modified" field.
the current behavior is correct, this ticket is really asking for a new field which we've never had

Comment by daniel.roberts@10gen.com [ 19/Feb/13 ]

nupdated still reports 1 even though document no change in version 2.4.0-rc1-pre-

db.soi.update({_id:5},{$setOnInsert : { ts:new ISODate(),b : "***UPDATEDFIELD***"}}, {upsert:true})
 
Tue Feb 19 13:02:35.141 [conn11] update test.soi query: { _id: 5.0 } update: { $setOnInsert: { ts: new Date(1361278955140), b: "***UPDATEDFIELD***" } } idhack:1 nupdated:1 fastmod:1 keyUpdates:0 locks(micros) w:42 0ms

Comment by Scott Hernandez (Inactive) [ 15/Feb/13 ]

They are also recorded to the oplog which I assume is a side-effect of this bug.

Comment by Alberto Lerner [ 15/Feb/13 ]

Some updates mods become no-ops, depending on the context in which they are executed, and the counters in those cases are off. This is a bug.

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