Dealing with schema changes in Mongoose

It’s funny though, MongoDB was born to respond to the schema problems in RDBMS. You don’t have to migrate anything, all you have to do is set the default value in the schema definition if the field is required.

new Schema({
    name: { type: string }
})

to:

new Schema({
    name: { type: string },
    birthplace: { type: string, required: true, default: 'neverborn' }
});

Leave a Comment