<commit_before># mongodb-migrations

> A Node.js migration framework for MongoDB with both programmatic and CLI API.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**  *generated with [DocToc](http://doctoc.herokuapp.com/)*

- [Installation](#installation)
- [Common Usage (CLI)](#common-usage-cli)
  - [Configuration](#configuration)
  - [Creating Migrations](#creating-migrations)
    - [Migration functions](#migration-functions)
  - [Sample migration file](#sample-migration-file)
  - [Running migrations](#running-migrations)
- [Programmatic usage](#programmatic-usage)
  - [Creating `Migrator` object](#creating-migrator-object)
    - [Custom logging](#custom-logging)
  - [Adding migrations](#adding-migrations)
    - [`migrator.add`](#migratoradd)
    - [`migrator.bulkAdd`](#migratorbulkadd)
  - [`migrator.migrate`](#migratormigrate)
  - [`migrator.runFromDir`](#migratorrunfromdir)
  - [`migrator.rollback`](#migratorrollback)
  - [`migrator.create`](#migratorcreate)
  - [`migrator.dispose`](#migratordispose)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## Installation

```bash
  npm install mongodb-migrations --save
```

## Common Usage (CLI)

The package installs a single CLI executable — `mm`.

When installing locally to your project this executable can be found at
`./node_modules/.bin/mm`.

When installing globally (normally not recommended) the executable should
automatically become accessible on your PATH.

### Configuration

The CLI app expects a configuration file to be present in the directory where
the app is being ran.

By default (if the configuration file is not set through the
command-line argument) the app checks `mm-config.json`, `mm-config.js`,
and `mm-config.coffee` files for existence.

File name can be passed through the means of `--config` parameter.
The path is relative to the current directory:

```bash
  mm --config=configs/mm.json
```

In case of `json` the file should contain valid JSON representation of the
configuration object.

In case of `js` or `coffee` the file should be a CommonJS module
exporting the configuration object. This is useful when you already have configuration
data (potentially in a different format) and want to avoid duplication. See `test/mm-config.coffee`
for an example of this usage.

In case of `coffee` the `coffee-script >= 1.7.0` package must be importable
from the current directory (include it as your project's dependency).

The configuration object can have the following keys:

* `host` — MongoDB host (_optional_ when using _replicaset_),
* `port` — MongoDB port (_optional_ when using _replicaset_),
* `db` — MongoDB database name,
* `ssl` _[optional]_ - boolean, if `true`, `'?ssl=true'` is added to the MongoDB URL,
* `user` _[optional]_ — MongoDB user name when authentication is required,
* `password` _[optional]_ — MongoDB password when authentication is required,
* `collection` — The name of the MongoDB collection to track
already ran migrations,
* `directory` — the directory (path relative to the current folder)
to store migration files in and read them from,
* `poolSize` - the size of the mongo connection pool,
* `replicaset` _[optional]_ - if using replica sets should be an object of the following structure:
```
name: 'rs-ds023680',
members: [
  {
    host: 'bee.boo.bar',
    port: 23680
  }
  {
    host: 'choo.choo',<commit_msg>Updated docs for timeout feature<commit_after># mongodb-migrations

> A Node.js migration framework for MongoDB with both programmatic and CLI API.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**  *generated with [DocToc](http://doctoc.herokuapp.com/)*

- [Installation](#installation)
- [Common Usage (CLI)](#common-usage-cli)
  - [Configuration](#configuration)
  - [Creating Migrations](#creating-migrations)
    - [Migration functions](#migration-functions)
  - [Sample migration file](#sample-migration-file)
  - [Running migrations](#running-migrations)
- [Programmatic usage](#programmatic-usage)
  - [Creating `Migrator` object](#creating-migrator-object)
    - [Custom logging](#custom-logging)
  - [Adding migrations](#adding-migrations)
    - [`migrator.add`](#migratoradd)
    - [`migrator.bulkAdd`](#migratorbulkadd)
  - [`migrator.migrate`](#migratormigrate)
  - [`migrator.runFromDir`](#migratorrunfromdir)
  - [`migrator.rollback`](#migratorrollback)
  - [`migrator.create`](#migratorcreate)
  - [`migrator.dispose`](#migratordispose)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## Installation

```bash
  npm install mongodb-migrations --save
```

## Common Usage (CLI)

The package installs a single CLI executable — `mm`.

When installing locally to your project this executable can be found at
`./node_modules/.bin/mm`.

When installing globally (normally not recommended) the executable should
automatically become accessible on your PATH.

### Configuration

The CLI app expects a configuration file to be present in the directory where
the app is being ran.

By default (if the configuration file is not set through the
command-line argument) the app checks `mm-config.json`, `mm-config.js`,
and `mm-config.coffee` files for existence.

File name can be passed through the means of `--config` parameter.
The path is relative to the current directory:

```bash
  mm --config=configs/mm.json
```

In case of `json` the file should contain valid JSON representation of the
configuration object.

In case of `js` or `coffee` the file should be a CommonJS module
exporting the configuration object. This is useful when you already have configuration
data (potentially in a different format) and want to avoid duplication. See `test/mm-config.coffee`
for an example of this usage.

In case of `coffee` the `coffee-script >= 1.7.0` package must be importable
from the current directory (include it as your project's dependency).

The configuration object can have the following keys:

* `host` — MongoDB host (_optional_ when using _replicaset_),
* `port` — MongoDB port (_optional_ when using _replicaset_),
* `db` — MongoDB database name,
* `ssl` _[optional]_ - boolean, if `true`, `'?ssl=true'` is added to the MongoDB URL,
* `user` _[optional]_ — MongoDB user name when authentication is required,
* `password` _[optional]_ — MongoDB password when authentication is required,
* `collection` — The name of the MongoDB collection to track
already ran migrations,
* `directory` — the directory (path relative to the current folder)
to store migration files in and read them from,
* `timeout` _[optional]_ — time in milliseconds after which migration should fail if `done()` is not called (use 0 to disable timeout) 
* `poolSize` - the size of the mongo connection pool,
* `replicaset` _[optional]_ - if using replica sets should be an object of the following structure:
```
name: 'rs-ds023680',
members: [
  {
    host: 'bee.boo.bar',
    port: 23680
  }
  {
    host: 'choo.choo',
{'fraction_non_alphanumeric': 0.11109560362875087, 'fraction_numerical': 0.004047452896022331, 'mean_word_length': 4.563664596273292, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '388176', 'n_tokens_mistral': 2224, 'n_tokens_neox': 2108, 'n_words': 818}