Created
November 17, 2018 19:35
-
-
Save smddzcy/49067d9363061176d7c1d1784faf231a to your computer and use it in GitHub Desktop.
Mongo bulk insert createdAt fields from ObjectIDs
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 collection = 'accounts'; | |
var bulk = db[collection].initializeUnorderedBulkOp(); | |
db[collection].find({}).forEach(row => { | |
const createdAt = dateFromObjectId(row._id); | |
bulk.find({ _id: ObjectID(row._id) }).updateOne({ $set: { createdAt } }) | |
}) | |
bulk.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment