At one of my collections I have an _id
field that stores numbers. The field was defined originally in the Mongoose model as String
. However, all the data concerning this field in the collection contains pure integers stored as strings. I want to preserve all the data in my collection while converting the type of this field (and all associated _id
's) from type String
to type Number
. Any suggestions as how to do that? Thanks.
MongoDB Type Conversion – How to Convert _id Field from String to Number
datatypesmongodbtype conversion
Related Question
- Mongodb – mongoexport not exporting all possible data
- PostgreSQL JSONB – Why Does JSONB Use More Space for Storing Integers?
- Mongodb – Reliability of mongodump
- Mongodb index keeps growing in size eventhough the collection has a TTL index
- MongoDB + Compass exporting strings and numbers “columns” with value of 1 as “true”(boolean) and 2 or null as “false” to CSV
Best Answer
This will do. You may want to add error handling as per your use case. Also make sure you have backup before migrating.