I have created a MongoDB collection with mongoose model using express (node.js) and it is working well. And now I want to restructure the model of the same collection. For that I have to delete the collection in the database and restart the server so that it is updating with new model. But I have live data which is in use. So how can I restructure the collection without deleting it.
Do we have any other way to resolve this issue which is not to delete the collection and restart the server to update the mongoose model in the collection?
My old Model looks like this:
new mongoose.Schema({
name: {type:String},
age: {type: String, required: true}
});
And I want this new model to be updated in the same collection:
new mongoose.Schema({
name: {type:String, unique: true},
age: {type: Number, required: true},
grade: {type:Number}
});