Hide
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)
|
Show
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 )