npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoomig

v1.1.7

Published

Yet another mongoose migration tool

Downloads

1,937

Readme

mongoomig

Build Status npm version Dependencies status

Description

Yet another mongoose migration tool

Key features

  • Async/await is default concept
  • Mongoose 4.11 support without deprecation warning
  • Could be configured through command line arguments, environment variables or config file
  • No dependencies, just one peer dependency - mongoose
  • Typescript support

Installation

Install with npm:

$ npm install mongoomig

Usage

  1. Create a migration. The following command creates a new migration file ./migrations/${date}-first-migration.js

    $ mongoomig create first-migration

  2. Write migration code

    'use strict';
    
    const User = require('../models/User');
    
    module.exports = {
      async up() {
        await User.create({ name: 'test-user' });
      },
    
      async down() {
        await User.deleteOne({ name: 'test-user' });
      },
    };
  3. Execute the migration

    $ mongoomig up

  4. (Optional) Add the migration command to package.json script:

"scripts": {
  "start": "node index.js",
  "migrate": "mongoomig up"
}

Also, you can check the example.

With Typescript

You can compile your modules before migration, or use ts-node instead:

npm install -D ts-node
mongomig up --require ts-node/register

Options

Command line

Usage: mongoomig [options] <command>

Commands:
  up [name]       Migrate up till given migration
  down [name]     Migrate down till given migration
  create <name>   Create a new migration
  list            Show migrations which are applied

Options:
  -c, --config=<path>      Load config from json or js file, default to
                             ./migrations/config.js
  -u, --url=<url>          Mongodb connection string
  --collection=<name>      Migrations collection, defaults to migrations
  -p, --path=<path>        Where your migrations are stored, defaults to
                             ./migrations
  --reconnectInterval=<ms> Try to reconnect every <ms>, default 300
  --reconnectTries=<count> Try to reconnect <count> times, default 100
  -r, --require=<module>   Require a module before loading migrations
  -s, --silent             Silent mode, defaults to false
  -d, --debug              Debug mode, defaults to false

Environment variables

Also, you can set a such options through environment variable. Just set MONGOOMIG_<OPTION_NAME_UPPERCASED>. For example, the MONGOOMIG_COLLECTION environment variable is equal to the collection option.

Additionally, mongoomig tries to load the url option from the MONGO_URL environment variable if another ways are not available.

Config file

Another way is to specify options inside a config. By default, this package tries to read a config from migrations/config.js. Here is the example of such a config:

'use strict';

module.exports = {
  url: 'mongodb://localhost/tiny-blog',
};

API

If you would like to run migrations from your code instead of command line, you can use API.

const Migration = require('mongoomig/lib/Migration');

const migration = new Migration({ path, url });
await migration.connect();
await migration.up();

A good example is index.js of this package.

License

Licensed under MIT.