I am using MongoDB 2, and I want to update multiple documents and upsert a value like processed:true
into the collection. But MongoDB c# api only allows us to
Try first removing all items to be inserted from the collection, and then calling insert:
var search = [];
arrayToInsert.forEach(function(v, k) {
search.push(v.hash); // my unique key is hash. you could use _id or whatever
})
collection.remove({
'hash' : {
$in : search
}
}, function(e, docs) {
collection.insert(arrayToInsert, function(e, docs) {
if (e) {
console.log("data failed to update ", e);
}
else {
console.log("data updated ");
}
});
})