[SERVER-46055] Error: the update operation document must contain atomic operators Created: 10/Feb/20  Updated: 27/Oct/23  Resolved: 24/Feb/20

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

Type: Bug Priority: Major - P3
Reporter: srinivas yalamanchili Assignee: Dmitry Agranat
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2020-02-10 at 10.12.53 AM.png    
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Was testing for something & found this issue, So tried to execute what's given in documentation https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/index.html#examples

So when executing aggregation pipeline in updateMany() getting this error every time on v4.2, Tried this on robo3T & mongo shell result is same. 

Query : (Same as given in documentation)

 

Insert :

 

db.members.insertMany([

{ "_id" : 1, "member" : "abc123", "status" : "A", "points" : 2, "misc1" : "note to self: confirm status", "misc2" : "Need to activate", "lastUpdate" : ISODate("2019-01-01T00:00:00Z") },
 { "_id" : 2, "member" : "xyz123", "status" : "A", "points" : 60, "misc1" : "reminder: ping me at 100pts", "misc2" : "Some random comment", "lastUpdate" : ISODate("2019-01-01T00:00:00Z") }
])

 

Update :

db.members.updateMany(
 { },
 [
 { $set: { status: "Modified", comments: [ "$misc1", "$misc2" ], lastUpdate: "$$NOW" } },
 { $unset: [ "misc1", "misc2" ] }
 ]
)

Working code (works with update) :

 
 

db.members.update({}, [{ $set: { status: "Modified", comments: ["$misc1", "$misc2"], lastUpdate: "$$NOW" } }, { $unset: ["misc1", "misc2"] }], false, true)

 

Participants:

 Description   

Getting 'Error: the update operation document must contain atomic operators' when executing aggregation pipeline thru .updateMany() on v4.2



 Comments   
Comment by srinivas yalamanchili [ 11/Feb/20 ]

@Dmitry Agranat : Ohh I've missed it, Yes I was using v`4.0.10` that seems to be an issue, with shell v`4.2` it's working fine. But what's weird is new `.update()` with aggregation pipeline does work with old shell (Vs) `.updateMany()` doesn't. Anyway thanks for help..

 

Comment by Dmitry Agranat [ 11/Feb/20 ]

Hi vtxn0504@gmail.com, I was able to reproduce this issue when using an older mongo shell version, with mongo shell 4.2 everything works fine. Can you try mongo shell 4.2 and let us know if everything works as expected?

Comment by srinivas yalamanchili [ 10/Feb/20 ]

@Dmitry Agranat : I'm getting same result with shell as well robo3T, Tried exactly the same thing what's given in documentation, Here is an image of my shell output..

 

 

Comment by Dmitry Agranat [ 10/Feb/20 ]

Hi vtxn0504@gmail.com,

Could you please provide mongod log as well as mongo shell output when executing these commands with mongo shell (not with robo3T)?

Regards,
Dima

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