[SERVER-31822] Update $push with empty $each reports nModified = 1 on MongoDB 3.4 Created: 03/Nov/17  Updated: 27/Oct/23  Resolved: 03/Jan/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.4.10
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Robert Guo (Inactive) Assignee: Backlog - Query Team (Inactive)
Resolution: Works as Designed Votes: 0
Labels: ufz
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

An update operation with an empty $push and an empty $each on an empty array gets reported as nModified = 1 on MongoDB 3.4, even though no documents have been modified.

The command result on 3.6 seems to be more correct.

There's no difference between the behavior of the command on 3.6 and previous versions.

> db.test.find()
{ "_id" : ObjectId("59fc96b0721d164cc5a90500"), "x" : [ ] }
 
// 3.4
> db.test.update({},{$push:{x:{$each:[]}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
 
// 3.6
> db.test.update({},{$push:{x:{$each:[]}}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })



 Comments   
Comment by Asya Kamsky [ 03/Jan/18 ]

Recommend "won't fix" as resolution.

Comment by Justin Seyster [ 06/Nov/17 ]

I would characterize this as a minor oversight in the previous implementation of the update system. The $push modifier in modifier_push.cpp does not check for no-op cases, because this is the only one, and it probably won't appear in practice. The new implementation does check, however:

https://github.com/mongodb/mongo/blob/c97dd9bc1f8652efcc41706b9b40a0829aed587a/src/mongo/db/update/push_node.cpp#L195

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