Skip to content

Instantly share code, notes, and snippets.

@crossgate10
Created August 30, 2021 05:51
Show Gist options
  • Save crossgate10/1ec92133305f009e6128805cb305d8e7 to your computer and use it in GitHub Desktop.
Save crossgate10/1ec92133305f009e6128805cb305d8e7 to your computer and use it in GitHub Desktop.
mongo_bulkwrite_in_datagrip
var bulkOps = [];
var allDocs = db.ranking.find().toArray();
allDocs.forEach(doc => {
var bettingOddsVal = parseFloat(doc.betting_odds).toFixed(2);
bulkOps.push({
updateOne: {
filter: { _id: doc._id },
update: { $set: { betting_odds_val: bettingOddsVal } }
}
});
if (bulkOps.length == 1000) {
db.ranking.bulkWrite(bulkOps);
bulkOps = [];
}
});
if (bulkOps.length > 0) {
db.ranking.bulkWrite(bulkOps);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment