I am trying to add new values to an array on all documents in a collection. I have tried this:
db.accounts_test.updateMany(
{
$push: {
friends:{
$each:[
'Fred',
'Shaggy'
]
}
}
},
{}
)
I am getting this error: Update document requires atomic operators
According to this page , $push is a valid update operator.
How should this query be constructed?
steevej
(Steeve Juneau)
May 22, 2024, 9:58pm
2
The query part, { } must be the first parameter. The update part, { $push : … } ,must be the second parameter. You got them in the wrong order.
2 Likes
Silly me, I don’t know how I missed that. Thank you.
steevej
(Steeve Juneau)
May 27, 2024, 12:52pm
4
You would not believe how may times I said that myself.
Guy_Swartwood:
Thank you.
You welcome. Please make sure you mark my post as the solution. So that the thread can eventually by closed. This gives other readers confidence that the recommendations are working.
system
(system)
Closed
March 4, 2025, 10:18pm
5
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.