/mongo-migrate-schema

MongoDB migration tool

Primary LanguageJavaScript

No longer maintained

[DEPRECATED] This repository is no longer maintained

While this project is fully functional, the dependencies are no longer up to date. You are still welcome to explore, learn, and use the code provided here.

Modus is dedicated to supporting the community with innovative ideas, best-practice patterns, and inspiring open source solutions. Check out the latest Modus Labs projects.

Modus Labs


mongo-migrate-schema

Description

This plugin can be used to migrate your MongoDB schema.

Notice

In your app require the module

var mongo-migrate-schema = require('mongo-migrate-schema');

And then call update function with options argument

mongo-migrate-schema.update({
    dbUri:'mongodb://localhost:27017/test'
    folder:__dirname + '/db'
});

In the given folder, put your update files.

Each file must be named following this pattern :

Note

[number]_[desciption].js

Example :

001_add_creation_date_field_default_value_today.js

Each file must export a function called execute

module.exports.execute = function (db, fn) {
    fn();
};

General options

Update options

dbUri

String

Uri of your MongoDB instance with the database name

folder

String

Absolute path where are your update files

Execute function parameters

db

MongoDB connection

fn

Callback function to invoke at the end of the upgrade. Can take in parameter an Error if an error occurred.