Skip to content

Instantly share code, notes, and snippets.

@smddzcy
Created November 17, 2018 19:35
Show Gist options
  • Save smddzcy/49067d9363061176d7c1d1784faf231a to your computer and use it in GitHub Desktop.
Save smddzcy/49067d9363061176d7c1d1784faf231a to your computer and use it in GitHub Desktop.
Mongo bulk insert createdAt fields from ObjectIDs
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