Dealing with schema changes in Mongoose

后端 未结 3 1433
轻奢々
轻奢々 2020-11-30 22:37

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

3条回答
  •  不知归路
    2020-11-30 23:00

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

提交回复
热议问题