Created
August 30, 2021 05:51
-
-
Save crossgate10/1ec92133305f009e6128805cb305d8e7 to your computer and use it in GitHub Desktop.
mongo_bulkwrite_in_datagrip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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