Sunday, 17 November 2019

Doing bulk operations with Mongoose

const docA = await Relation.findOneAndRemove( { master: masterMember.id, slave: slaveMember.id } ) const docB = await Relation.findOneAndRemove( { slave: masterMember.id, master: slaveMember.id } ) await Member.findOneAndUpdate( { _id: masterMember.id }, { $pull: { Relations: docA._id }} ) await Member.findOneAndUpdate( { _id: slaveMember.id }, { $pull: { Relations: docB._id }} ) I am wondering if I can combine the four into a single bulk operation. I think I can combine the last two into a single bulk operation, but I am not sure if it's possible to do all four in a single bulk operation. What's the most efficient way to do this?

Submitted November 18, 2019 at 02:30AM by jesusscript

No comments:

Post a Comment