Dealing with schema changes in Mongoose

mahemoff picture mahemoff · Oct 1, 2011 · Viewed 32.1k times · Source

What's the best practice (or tool) for updating/migrating Mongoose schemas as the application evolves?

Answer

vimdude picture vimdude · Jan 7, 2012

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' }
});