So I've seen this question asked before, but when I tried the solution myself it didn't seem to work. Update multiple documents by id set. Mongoose
Based on the solution above, I wrote this code:
listOfParticipant = [ "5f50a1df63fe0000ed98b393", "5f69cc7cda1d549f9edcc8bb","5f3207204450b32620449657","5f3207204450b32620449657", "5f39585030027a3d57f0cc0e", "5e719e4715c7865bcb00c820", "5f32d0ab59eccf22d2e2f29f" ],
User.update( {_id: {$in: listOfParticipant}},
{$addToSet: {
userNotification: notification
}
},
{multi: true}
)
But it doesn't seem to work, could anyone help me out in finding out why?
So this query is correct. The reason it wasn't working is because I was trying to chain it with another MongoDB call. I was trying to use it inside the callback function when I updated another MongoDB collection. Once I made this into its own separate function, it worked just fine!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.