I want to execute the following two updates in single update query.
// delete the user with (requestID) from friends
await User.updateOne({
_id: id,
}, {
$pull: { friends: requestID }
})
// delete the user with (id) from friends
await User.updateOne({
_id: requestID,
}, {
$pull: { friends: id }
})
I want it to be like this:
updateMany({
// delete the user with (requestID) from friends
// delete the user with (id) from friends
})
2
Answers
You can use MongoDB’s bulkWrite method for this –
bulkWrite documentation
Another option:
Explained:
$pull the requested different users joining all conditions with $or
playground