Skip to content

Instantly share code, notes, and snippets.

@xexi
Created February 2, 2017 07:49
Show Gist options
  • Save xexi/a09b54b1a9e04801e03ad3c164616bce to your computer and use it in GitHub Desktop.
Save xexi/a09b54b1a9e04801e03ad3c164616bce to your computer and use it in GitHub Desktop.
let bulk = db.collection('myCollection').initializeOrderedBulkOp();
for(let i=0; i < arr.length; i++){
bulk.find( {findData: arr[i]} ).upsert().updateOne(
{
$set: { modData: 'yolo' }
}
);
}
bulk.execute(function(err){
db.close();
if(err){
// do err
} else {
// well done
}
});
@xexi
Copy link
Author

xexi commented Feb 2, 2017

from my experience sometimes this operation not granted (mongo v3.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment