Given this update statement
const result = await Post.updateOne({_id: postId},{
$pull: {reacts: {publisher: req.query.publisher}},
$inc: {postPoints: - reactsEnum[ReactType]}
});
I want to get the react Type of the react pulled from the array in the $pull operation. is it possible to do so or to do something similar?
2
Answers
In MongoDB, directly getting the index of a specific element in an array while performing an update with $pull is not supported in a single operation. To achieve this, you would need to first fetch the original document, find the index of the element you want to remove in the array, and then perform the update with $pull. This requires multiple database operations.
Code: