How to properly handle mongoose schema migrations?

前端 未结 3 875
温柔的废话
温柔的废话 2020-12-23 16:49

I\'m completely new to MongoDB & Mongoose and can\'t seem to find an answer as to how to handle migrations when a schema changes.

I\'m used to running migration

3条回答
  •  太阳男子
    2020-12-23 17:19

    If you're used to SQL type migrations or Rails-like migrations then you'll find my cli tool migrate-mongoose the right fit for you.

    It allows you to write migrations with an up and a down function and manages the state for you based on success and failure of your migrations.

    It also supports ES6 if you're using ES 2015 syntax.

    You get access to your mongoose models via the this object, making it easy to make the changes you need to your models and schemas.

提交回复
热议问题