New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-migration

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-migration

Data migration tool for Mongoose

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

mongoose-migration

Install

npm install -save mongoose-migration

usage

Init configuration

migrate init

Create a migration

migrate create <description>

Example: migrate create "Add createdAt to users collection"

Edit Migration File

Open up your migration file (created on the previous step). It should have a default up and down function.

Example:

exports.up = function(next) {
  next();
};

exports.down = function(next) {
  next();
};

To load a model you should call this.model(<model name>)

Example:

exports.up = function(next) {
  this
    .model('User')
    .update(
      {},
      {
        $set: { createdAt: Date.now() }
      },
      {
        multi: true,
        strict: false
      },
      function (error, numberAffected, raw) {
        if (error) {
          console.error(error);
        }
        console.log('The number of updated documents was %d', numberAffected);
        console.log('The raw response from Mongo was ', raw);
        next();
      }
    );
};

exports.down = function(next) {
  this
    .model('User')
    .update(
      {},
      {
        $unset: { createdAt: 1 }
      },
      {
        multi: true,
        strict: false
      },
      function (error, numberAffected, raw) {
        if (error) {
          console.error(error);
        }
        console.log('The number of updated documents was %d', numberAffected);
        console.log('The raw response from Mongo was ', raw);
        next();
      }
    );
};

Perform Migration

migrate

or

migrate up <number of migrations to perform>

Rollback Migration

migrate down

or

migrate down <number of migrations to rollback>

Help

migrate -h

Keywords

FAQs

Package last updated on 25 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc