mongoose-model-migration
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

mongoose-model-migration

Build Status Code Coverage MIT License semantic-release Renovate enabled NPM Package NPM Package Downloads

Utility library that provides some basic mechanisms for versioning and upgrading mongoose models in Node.js

Installation

Using npm:

npm install --save mongoose-model-migration

Using yarn

yarn add mongoose-model-migration

Usage

In ES6 / Typescript

import { migrateModel, migrateCollection } from 'mongoose-model-migration';

Basic Collection 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);

Collection migration options

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'

Package Sidebar

Install

npm i mongoose-model-migration

Weekly Downloads

115

Version

3.0.0

License

MIT

Unpacked Size

360 kB

Total Files

28

Last publish

Collaborators

  • ivan.hell