Skip to content

Instantly share code, notes, and snippets.

@bobagold
Last active June 28, 2017 16:00
Show Gist options
  • Save bobagold/05537b6e8743b72d390232072b34d39c to your computer and use it in GitHub Desktop.
Save bobagold/05537b6e8743b72d390232072b34d39c to your computer and use it in GitHub Desktop.
how to change type of _id field in an existing mongo collection from ObjectId to String with the same value
// assuming the collection name is translations
db.translations.find({_id: {$type: 7}}).forEach((r) => {const n = Object.assign({}, r, {_id: r._id.str}); db.translations.remove(r); db.translations.save(n);})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment