Utility library that provides some basic mechanisms for versioning and upgrading mongoose models in Node.js
Using npm:
npm install --save mongoose-model-migration
Using yarn
yarn add mongoose-model-migration
In ES6 / Typescript
import { migrateModel, migrateCollection } from 'mongoose-model-migration';
import { migrateCollection, CollectionMigrationHandler } from 'mongoose-model-migration';
const migrationHandler: CollectionMigrationHandler = {
up: async (db, collection, fromVersion, toVersion) => {
// ... call upgrate operations for collection
},
down: async (db, collection, fromVersion, toVersion) => {
// ... call downgrade operations for collection
}
};
await migrateCollection('users', 2, migrationHandler);
migrateCollection
accepts an optional options object as 4th parameter:
option | Description |
---|---|
db | Optionally specify the mongodb database that should be used during migration. Defaults to the global mongoose connection.db |
versionCollectionName | Optionally specify the collection name that should be used to store version information. Defaults to collectionName + '.version' |