let ops = [];
result.forEach(item => {
ops.push({
updateOne: {
filter: {'_id': item._id},
update: {
$set: {
_id: item._id,
owner: item.owner,
title: item.title
}
},
upsert: true
}
})
});
postsModel.bulkWrite(ops)
.then(bulkWriteOpResult => {
console.log('BULK update OK');
console.log(JSON.stringify(bulkWriteOpResult, null, 2));
})
.catch(err => {
console.log('BULK update error');
console.log(JSON.stringify(err, null, 2));
});
filter: { _id: item._id },
update: {
$set: { a: item.a, b: item.b},
$setOnInsert: { a: item.a, b: item.b }
},