I have a MongoDB database with two schemas - users and posts. It used to look like this:
username: {type: String},
following: {type: [String], ref: 'users'}
user_id: {type: String, ref: 'users'}
comment: {type: String}
But now I've decided to change reference fields' types from String to ObjectId so now I have:
username: {type: String},
following: {type: [Schema.Types.ObjectId], ref: 'users'}
user_id: {type: Schema.Types.ObjectId, ref: 'users'}
comment: {type: String}
But the old data in the database is still stored as Strings. How can I migrate that data properly?
I use Mongoose to query the database from my code.
ObjectIdhex values?