Miss any of our Open RFC calls?Watch the recordings here! »

@bifot/mongodb-migrator

1.0.1 • Public • Published

@bifot/mongodb-migrator

MongoDB super-simple migrator.

Install

$ npm i @bifot/mongodb-migrator -S

Usage

const Migrator = require('@bifot/mongodb-migrator');
 
const migrator = new Migrator({
  db: {
    host: 'localhost',
    port: 27017,
    user: 'admin',
    password: '123456',
    database: 'my-app',
  },
  collections: ['users'],
});
 
const migrate = async () => {
  await migrator.users.addColumn('lastName', '');
  await migrator.users.deleteColumn('age');
  await migrator.users.renameColumn('name', 'firstName');
};
 
migrate();

API

Migrator methods

constructor(settings)

Create instance of migrator with specified collections. After creating, you can use collections methods (e.g. users.addColumn, books.deleteColumn).

Collection methods

.addColumn(column[, defaultValue])

Add column with optional default value.

// add column 'lastName' with default value ''
await migrator.users.addColumn('lastName', '');

.deleteColumn(column)

Delete column.

// delete column 'age'
await migrator.users.deleteColumn('age');

.renameColumn(oldColumn, newColumn)

Rename column.

// rename column 'name' to 'firstName'
await migrator.users.renameColumn('name', 'firstName');

License

MIT.

Install

npm i @bifot/mongodb-migrator

DownloadsWeekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

2.98 kB

Total Files

3

Last publish

Collaborators

  • avatar