Last active
June 28, 2017 16:00
-
-
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
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
// 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