I have an object that looks like this.
_id: objectId,
vip:
[
{
uid:{type: Schema.Types.ObjectId, ref: 'User'},
time:Date,
paid:{type:Boolean,default:false}
}
]
My goal is to mark vip.$.paid to be true by providing a array of uid in mongoose node.js
I know that to update one single document with one uid parameter is like this
User.findOneAndUpdate({_id:id,"vip.$.uid":uid}, {$set: {"vip.$.paid" : true}})
but given a array of uids, updating the nested documents could be simply like
for (uid in uids){
User.findOneAndUpdate({_id:id,"vip.$.uid":uid}, {$set: {"vip.$.paid" : true}})
}
but this is not effecient enough, how would I accomplish this ?