// record the operations
var bulkOps = [];
for(var i = 0; i < array.length; i ++){
// each operation
let updateMsg = {
'updateOne': {
'filter': {'_id': array[i]},
'update': {$push: {'children': mongoose.Types.ObjectId(child_id)}},
'upsert': true,
}
};
bulkOps.push(updateMsg);
};
//execute those operations
Message.bulkWrite(bulkOps)
.then( bulkWriteOpResult => {
console.log('Updated');
})
.catch( err => {
console.log('Failed to update');
});
mongoose bulkWrite 范例
最新推荐文章于 2020-10-22 11:17:00 发布