🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

migrate-mongo

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

migrate-mongo

A database migration tool for MongoDB in Node

12.1.3
latest
Version published
Weekly downloads
166K
13.74%
Maintainers
0
Weekly downloads
 
Created

What is migrate-mongo?

The migrate-mongo npm package is a tool for managing MongoDB database migrations. It allows developers to create, run, and manage database schema changes in a controlled and versioned manner.

What are migrate-mongo's main functionalities?

Create a new migration

This feature allows you to create a new migration file. The migration file will be created in the configured migrations directory with a timestamp in its filename.

const migrateMongo = require('migrate-mongo');
migrateMongo.create('my-new-migration').then(() => {
  console.log('Migration created');
});

Run migrations

This feature runs all pending migrations. It ensures that your database schema is up-to-date with the latest changes.

const migrateMongo = require('migrate-mongo');
migrateMongo.up().then((migrated) => {
  console.log('Migrations up:', migrated);
});

Rollback migrations

This feature rolls back the last applied migration. It is useful for undoing changes in case of errors or issues.

const migrateMongo = require('migrate-mongo');
migrateMongo.down().then((migrated) => {
  console.log('Migrations down:', migrated);
});

Configure migrate-mongo

This feature allows you to configure the connection to your MongoDB database and other settings like the migrations directory and changelog collection name.

const migrateMongo = require('migrate-mongo');
const config = {
  mongodb: {
    url: 'mongodb://localhost:27017/mydatabase',
    databaseName: 'mydatabase',
    options: {
      useNewUrlParser: true,
      useUnifiedTopology: true
    }
  },
  migrationsDir: 'migrations',
  changelogCollectionName: 'changelog'
};
migrateMongo.config.set(config);

Other packages similar to migrate-mongo

FAQs

Package last updated on 03 Feb 2025

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