[SERVER-8537] Incorrect result numbers for partial updates if there is an error Created: 12/Feb/13  Updated: 06/Dec/22

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

Type: Bug Priority: Major - P3
Reporter: Adinoyi Omuya Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: ShardingRoughEdges, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Operating System: ALL
Participants:

 Description   

When a multi update is applied to a collection where the operation is unable to be applied to all documents (e.g. a $inc on an array field), getLastError() returns "n" : 0 with the error but the operation still updates documents that it is able to update. The multi-update returns as soon as it fails to apply an operation.

Expected behavior: It should report "n" : `count of the number of documents it was able to update` as well as the error.

Actual behavior: Reports error and "n" : 0.

The example below updates 1/2 documents, but returns "n" : 0

>use test
>db.c.insert({a:3,b:4})
>db.c.insert({a:[3,5],b:3})
>db.c.find()
{ "_id" : ObjectId("511d4e76242fb0dfc20856cc"), "a" : [ 3, 5 ], "b" : 3 }
{ "_id" : ObjectId("511d4e9f242fb0dfc20856cd"), "a" : 3, "b" : 4 }
>db.c.update({}, {$inc:{a:1,b:6}}, {multi:true});db.getLastErrorObj();
{
	"err" : "Cannot apply $inc modifier to non-number",
	"code" : 10140,
	"n" : 0,
	"connectionId" : 1,
	"ok" : 1
}
> db.c.find()
{ "_id" : ObjectId("511d4ed0242fb0dfc20856ce"), "a" : 4, "b" : 10 }
{ "_id" : ObjectId("511d4edd242fb0dfc20856cf"), "a" : [ 3, 5 ], "b" : 3 }



 Comments   
Comment by Asya Kamsky [ 13/Jul/18 ]

This doesn't seem to have anything to do with sharding to moving to Query backlog.

With 4.0 it looks like behavior is similar:

db.c.update({}, {$inc:{a:1,b:6}}, {multi:true})db.c.update({}, {$inc:{a:1,b:6}}, {multi:true})
WriteResult({
    "nMatched" : 0,
    "nUpserted" : 0,
    "nModified" : 0,
    "writeError" : {
        "code" : 14,
        "errmsg" : "Cannot apply $inc to a value of non-numeric type. {_id: ObjectId('5b47ee4f0e2b9943cf41894c')} has the field 'a' of non-numeric type array" }}) 

Comment by Asya Kamsky [ 13/Jul/18 ]

Why is this on sharding backlog rather than query?

 

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