xxxxxxxxxx
const contestants = await Contestant.find(
{ lottery: last[1]._id },
);
console.log(contestants);
const bulkArray = contestants.map((contestant) => {
return {
updateOne: {
filter: { _id: contestant.user },
update: {
$inc:{balance: contestant.prize},
},
},
};
});
// console.log(bulkArray);
// await User.updateMany({ _id: { $in: contestants.map((contestant) => contestant.user) } }, { $inc: { balance: 25 } , multi:true});
await User.bulkWrite(bulkArray);
return res.send("Lottery Drawn");
xxxxxxxxxx
db.collectionName.updateMany(
{
_id:
{
$in:
[
ObjectId("your object id"),
ObjectId("your object id")
]
}
},
{
$inc: { quantity: 100 }
})