{"id":13531167,"url":"https://github.com/seppevs/migrate-mongo","last_synced_at":"2025-10-08T01:18:50.266Z","repository":{"id":9067100,"uuid":"60646932","full_name":"seppevs/migrate-mongo","owner":"seppevs","description":"A database migration tool for MongoDB in Node","archived":false,"fork":false,"pushed_at":"2025-02-03T12:34:36.000Z","size":964,"stargazers_count":1001,"open_issues_count":65,"forks_count":184,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-10-06T14:56:17.522Z","etag":null,"topics":["database","database-migrations","migrate","migrations","mongo","mongodb","node","npm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seppevs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-07T21:14:33.000Z","updated_at":"2025-09-30T18:47:59.000Z","dependencies_parsed_at":"2024-01-23T17:13:49.455Z","dependency_job_id":"8e01ef1d-7411-454a-9bfe-81f503247885","html_url":"https://github.com/seppevs/migrate-mongo","commit_stats":{"total_commits":234,"total_committers":27,"mean_commits":8.666666666666666,"dds":"0.47435897435897434","last_synced_commit":"3753b2bc52436d06482efc8442d10e93960b83f8"},"previous_names":[],"tags_count":72,"template":false,"template_full_name":null,"purl":"pkg:github/seppevs/migrate-mongo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fmigrate-mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fmigrate-mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fmigrate-mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fmigrate-mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seppevs","download_url":"https://codeload.github.com/seppevs/migrate-mongo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fmigrate-mongo/sbom","scorecard":{"id":811703,"data":{"date":"2025-08-11","repo":{"name":"github.com/seppevs/migrate-mongo","commit":"5a40ba25fc53ba920d97e038dfc7d4eeba3ca3d6"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.3,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":2,"reason":"Found 8/28 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":2,"reason":"8 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-xffm-g5w8-qvg7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T13:21:14.420Z","repository_id":9067100,"created_at":"2025-08-23T13:21:14.420Z","updated_at":"2025-08-23T13:21:14.420Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278734435,"owners_count":26036404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","database-migrations","migrate","migrations","mongo","mongodb","node","npm"],"created_at":"2024-08-01T07:01:00.601Z","updated_at":"2025-10-08T01:18:50.237Z","avatar_url":"https://github.com/seppevs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Tools"],"sub_categories":["Development"],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"/migrate-mongo-logo.png\" alt=\"migrate-mongo database migration tool for Node.js\"/\u003e\n\n[![Coverage Status](https://coveralls.io/repos/github/seppevs/migrate-mongo/badge.svg?branch=master)](https://coveralls.io/r/seppevs/migrate-mongo) [![NPM](https://img.shields.io/npm/v/migrate-mongo.svg?style=flat)](https://www.npmjs.org/package/migrate-mongo) [![Downloads](https://img.shields.io/npm/dm/migrate-mongo.svg?style=flat)](https://www.npmjs.org/package/migrate-mongo) [![Known Vulnerabilities](https://snyk.io/test/github/seppevs/migrate-mongo/badge.svg)](https://snyk.io/test/github/seppevs/migrate-mongo)\n\nmigrate-mongo is a database migration tool for MongoDB running in Node.js \n\n\u003c/p\u003e\n    \n## Installation\n````bash\n$ npm install -g migrate-mongo\n````\n\n## CLI Usage\n````\n$ migrate-mongo\nUsage: migrate-mongo [options] [command]\n\n\n  Commands:\n\n    init                  initialize a new migration project\n    create [description]  create a new database migration with the provided description\n    up [options]          run all unapplied database migrations\n    down [options]        undo the last applied database migration\n    status [options]      print the changelog of the database\n\n  Options:\n\n    -h, --help     output usage information\n    -V, --version  output the version number\n````\n\n## Basic Usage\n### Initialize a new project\nMake sure you have [Node.js](https://nodejs.org/en/) 10 (or higher) installed.  \n\nCreate a directory where you want to store your migrations for your mongo database (eg. 'albums' here) and cd into it\n````bash\n$ mkdir albums-migrations\n$ cd albums-migrations\n````\n\nInitialize a new migrate-mongo project\n````bash\n$ migrate-mongo init\nInitialization successful. Please edit the generated migrate-mongo-config.js file\n````\n\nThe above command did two things: \n1. create a sample 'migrate-mongo-config.js' file and \n2. create a 'migrations' directory\n\nEdit the migrate-mongo-config.js file. An object or promise can be returned. Make sure you change the mongodb url: \n````javascript\n// In this file you can configure migrate-mongo\n\nmodule.exports = {\n  mongodb: {\n    // TODO Change (or review) the url to your MongoDB:\n    url: \"mongodb://localhost:27017\",\n\n    // TODO Change this to your database name:\n    databaseName: \"YOURDATABASENAME\",\n\n    options: {\n      useNewUrlParser: true // removes a deprecation warning when connecting\n      //   connectTimeoutMS: 3600000, // increase connection timeout to 1 hour\n      //   socketTimeoutMS: 3600000, // increase socket timeout to 1 hour\n    }\n  },\n\n  // The migrations dir, can be an relative or absolute path. Only edit this when really necessary.\n  migrationsDir: \"migrations\",\n\n  // The mongodb collection where the applied changes are stored. Only edit this when really necessary.\n  changelogCollectionName: \"changelog\",\n\n  // The file extension to create migrations and search for in migration dir \n  migrationFileExtension: \".js\",\n\n  // Enable the algorithm to create a checksum of the file contents and use that in the comparison to determin\n  // if the file should be run.  Requires that scripts are coded to be run multiple times.\n  useFileHash: false\n\n  // The mongodb collection where the lock will be created.\n  lockCollectionName: \"changelog_lock\",\n\n  // The value in seconds for the TTL index that will be used for the lock. Value of 0 will disable the feature.\n  lockTtl: 0\n};\n````\n\nAlternatively, you can also encode your database name in the url (and leave out the `databaseName` property):\n````\n        url: \"mongodb://localhost:27017/YOURDATABASE\",\n````\n\n### Creating a new migration script\nTo create a new database migration script, just run the ````migrate-mongo create [description]```` command.\n\nFor example:\n````bash\n$ migrate-mongo create blacklist_the_beatles\nCreated: migrations/20160608155948-blacklist_the_beatles.js\n````\n\nA new migration file is created in the 'migrations' directory:\n````javascript\nmodule.exports = {\n  /**\n   * @param db {import('mongodb').Db}\n   * @param client {import('mongodb').MongoClient}\n   * @returns {Promise\u003cvoid\u003e}\n   */\n  up(db, client) {\n    // TODO write your migration here. Return a Promise (and/or use async \u0026 await).\n    // See https://github.com/seppevs/migrate-mongo/#creating-a-new-migration-script\n    // Example:\n    // return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}});\n  },\n\n  /**\n   * @param db {import('mongodb').Db}\n   * @param client {import('mongodb').MongoClient}\n   * @returns {Promise\u003cvoid\u003e}\n   */\n  down(db, client) {\n    // TODO write the statements to rollback your migration (if possible)\n    // Example:\n    // return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}});\n  }\n};\n````\n\nEdit this content so it actually performs changes to your database. Don't forget to write the down part as well.\nThe ````db```` object contains [the official MongoDB db object](https://www.npmjs.com/package/mongodb)\nThe ````client```` object is a [MongoClient](https://mongodb.github.io/node-mongodb-native/3.3/api/MongoClient.html) instance (which you can omit if you don't use it).\n\nThere are 3 options to implement the `up` and `down` functions of your migration: \n1. Return a Promises\n2. Use async-await \n3. Call a callback (DEPRECATED!)\n\nAlways make sure the implementation matches the function signature:\n* `function up(db, client) { /* */ }` should return `Promise`\n* `async function up(db, client) { /* */ }` should contain `await` keyword(s) and return `Promise`\n* `function up(db, client, next) { /* */ }` should callback `next`\n\n#### Example 1: Return a Promise\n````javascript\nmodule.exports = {\n  up(db) {\n    return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}});\n  },\n\n  down(db) {\n    return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}});\n  }\n};\n````\n\n#### Example 2: Use async \u0026 await\nAsync \u0026 await is especially useful if you want to perform multiple operations against your MongoDB in one migration.\n\n````javascript\nmodule.exports = {\n  async up(db) {\n    await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}});\n    await db.collection('albums').updateOne({artist: 'The Doors'}, {$set: {stars: 5}});\n  },\n\n  async down(db) {\n    await db.collection('albums').updateOne({artist: 'The Doors'}, {$set: {stars: 0}});\n    await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}});\n  },\n};\n````\n\n#### Example 3: Call a callback (deprecated)\nCallbacks are supported for backwards compatibility.\nNew migration scripts should be written using Promises and/or async \u0026 await. It's easier to read and write.\n\n````javascript\nmodule.exports = {\n  up(db, callback) {\n    return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}}, callback);\n  },\n\n  down(db, callback) {\n    return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}}, callback);\n  }\n};\n````\n\n#### Overriding the sample migration\nTo override the content of the sample migration that will be created by the `create` command, \ncreate a file **`sample-migration.js`** in the migrations directory.\n\n### Checking the status of the migrations\nAt any time, you can check which migrations are applied (or not)\n\n````bash\n$ migrate-mongo status\n┌─────────────────────────────────────────┬────────────┐\n│ Filename                                │ Applied At │\n├─────────────────────────────────────────┼────────────┤\n│ 20160608155948-blacklist_the_beatles.js │ PENDING    │\n└─────────────────────────────────────────┴────────────┘\n\n````\n\n\n### Migrate up\nThis command will apply all pending migrations\n````bash\n$ migrate-mongo up\nMIGRATED UP: 20160608155948-blacklist_the_beatles.js\n````\n\nIf an an error occurred, it will stop and won't continue with the rest of the pending migrations\n\nIf we check the status again, we can see the last migration was successfully applied:\n````bash\n$ migrate-mongo status\n┌─────────────────────────────────────────┬──────────────────────────┐\n│ Filename                                │ Applied At               │\n├─────────────────────────────────────────┼──────────────────────────┤\n│ 20160608155948-blacklist_the_beatles.js │ 2016-06-08T20:13:30.415Z │\n└─────────────────────────────────────────┴──────────────────────────┘\n````\n\n### Migrate down\nWith this command, migrate-mongo will revert (only) the last applied migration\n\n````bash\n$ migrate-mongo down\nMIGRATED DOWN: 20160608155948-blacklist_the_beatles.js\n````\n\nIf we check the status again, we see that the reverted migration is pending again:\n````bash\n$ migrate-mongo status\n┌─────────────────────────────────────────┬────────────┐\n│ Filename                                │ Applied At │\n├─────────────────────────────────────────┼────────────┤\n│ 20160608155948-blacklist_the_beatles.js │ PENDING    │\n└─────────────────────────────────────────┴────────────┘\n````\n\n#### Migrate down all scripts from a same migration\nWith the flag -b (--block), migrate-mongo will revert all scripts of the last migration.\n````bash\n$ migrate-mongo down -b\n````\n\n## Advanced Features\n\n### Using a custom config file\nAll actions (except ```init```) accept an optional ````-f```` or ````--file```` option to specify a path to a custom config file.\nBy default, migrate-mongo will look for a ````migrate-mongo-config.js```` config file in of the current directory.\n\n#### Example:\n\n````bash\n$ migrate-mongo status -f '~/configs/albums-migrations.js'\n┌─────────────────────────────────────────┬────────────┐\n│ Filename                                │ Applied At │\n├─────────────────────────────────────────┼────────────┤\n│ 20160608155948-blacklist_the_beatles.js │ PENDING    │\n└─────────────────────────────────────────┴────────────┘\n\n````\n\n### Using npm packages in your migration scripts\nYou can use use Node.js modules (or require other modules) in your migration scripts.\nIt's even possible to use npm modules, just provide a `package.json` file in the root of your migration project:\n\n````bash\n$ cd albums-migrations\n$ npm init --yes\n````\n\nNow you have a package.json file, and you can install your favorite npm modules that might help you in your migration scripts.\nFor example, one of the very useful [promise-fun](https://github.com/sindresorhus/promise-fun) npm modules.\n\n\n### Using ESM (ECMAScript Modules) instead of CommonJS\nSince migrate-mongo 7.0.0, it's possible to use ESM instead of CommonJS.\n\n#### Using ESM when initializing a new project\nPass the `-m esm` option to the `init` action:\n````bash\n$ migrate-mongo init -m esm\n````\n\nIt's also required to have package.json file in the root of your project with `\"type\": \"module\"`.\nCreate a new package.json file:\n````bash\n$ npm init --yes\n````\n\nThen edit this package.json file, and add:\n````bash\n\"type\": \"module\"\n````\n\nWhen you create migration files with `migrate-mongo create`, they will be prepared for you in ESM style.\n\nPlease note that CommonJS is still the default module loading system.\n\n### Using MongoDB's Transactions API\nYou can make use of the [MongoDB Transaction API](https://docs.mongodb.com/manual/core/transactions/) in your migration scripts.\n\nNote: this requires both:\n- MongoDB 4.0 or higher \n- migrate-mongo 7.0.0 or higher\n\nmigrate-mongo will call your migration `up` and `down` function with a second argument: `client`.\nThis `client` argument is an [MongoClient](https://mongodb.github.io/node-mongodb-native/3.3/api/MongoClient.html) instance, it gives you access to the `startSession` function.\n\nExample:\n\n````javascript\nmodule.exports = {\n  async up(db, client) {\n    const session = client.startSession();\n    try {\n        await session.withTransaction(async () =\u003e {\n            await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}}, {session});\n            await db.collection('albums').updateOne({artist: 'The Doors'}, {$set: {stars: 5}}, {session});\n        });\n    } finally {\n      await session.endSession();\n    }\n  },\n\n  async down(db, client) {\n    const session = client.startSession();\n    try {\n        await session.withTransaction(async () =\u003e {\n            await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}}, {session});\n            await db.collection('albums').updateOne({artist: 'The Doors'}, {$set: {stars: 0}}, {session});\n        });\n    } finally {\n      await session.endSession();\n    }\n  },\n};\n````\n\n### Using a file hash algorithm to enable re-running updated files\nThere are use cases where it may make sense to not treat scripts as immutable items.  An example would be a simple collection with lookup values where you just can wipe and recreate the entire collection all at the same time.\n\n```javascript\nuseFileHash: true\n```\n\nSet this config value to will enable tracking a hash of the file contents and will run a file with the same name again as long as the file contents have changes.  Setting this flag changes the behavior for every script and if this is enabled each script needs to be written in a manner where it can be re-run safefly.  A script of the same name and hash will not be executed again, only if the hash changes.\n\nNow the status will also include the file hash in the output\n\n```bash\n┌────────────────────────────────────────┬──────────────────────────────────────────────────────────────────┬──────────────────────────┐\n│ Filename                               │ Hash                                                             │ Applied At               │\n├────────────────────────────────────────┼──────────────────────────────────────────────────────────────────┼──────────────────────────┤\n│ 20160608155948-blacklist_the_beatles.js│ 7625a0220d552dbeb42e26fdab61d8c7ef54ac3a052254588c267e42e9fa876d │ 2021-03-04T15:40:22.732Z │\n└────────────────────────────────────────┴──────────────────────────────────────────────────────────────────┴──────────────────────────┘\n\n```\n\n### Version\nTo know which version of migrate-mongo you're running, just pass the `version` option:\n\n````bash\n$ migrate-mongo version\n````\n\n## API Usage\n\n```javascript\nconst {\n  init,\n  create,\n  database,\n  config,\n  up,\n  down,\n  status\n} = require('migrate-mongo');\n```\n\n### `init() → Promise`\n\nInitialize a new migrate-mongo project\n```javascript\nawait init();\n```\n\nThe above command did two things: \n1. create a sample `migrate-mongo-config.js` file and \n2. create a `migrations` directory\n\nEdit the `migrate-mongo-config.js` file. Make sure you change the mongodb url.\n\n### `create(description) → Promise\u003cfileName\u003e`\n\nFor example:\n```javascript\nconst fileName = await create('blacklist_the_beatles');\nconsole.log('Created:', fileName);\n```\n\nA new migration file is created in the `migrations` directory.\n\n### `database.connect() → Promise\u003c{db: MongoDb, client: MongoClient}\u003e`\n\nConnect to a mongo database using the connection settings from the `migrate-mongo-config.js` file.\n\n```javascript\nconst { db, client } = await database.connect();\n```\n\n### `config.read() → Promise\u003cJSON\u003e`\n\nRead connection settings from the `migrate-mongo-config.js` file.\n\n```javascript\nconst mongoConnectionSettings = await config.read();\n```\n\n### `config.set(yourConfigObject)`\n\nTell migrate-mongo NOT to use the `migrate-mongo-config.js` file, but instead use the config object passed as the first argument of this function.\nWhen using this feature, please do this at the very beginning of your program.\n\nExample:\n```javascript\nconst { config, up } = require('../lib/migrate-mongo');\n\nconst myConfig = {\n    mongodb: {\n        url: \"mongodb://localhost:27017/mydatabase\",\n        options: { useNewUrlParser: true }\n    },\n    migrationsDir: \"migrations\",\n    changelogCollectionName: \"changelog\",\n    migrationFileExtension: \".js\"\n};\n\nconfig.set(myConfig);\n\n// then, use the API as you normally would, eg:\nawait up();\n```\n\n### `up(MongoDb, MongoClient) → Promise\u003cArray\u003cfileName\u003e\u003e`\n\nApply all pending migrations\n\n```javascript\nconst { db, client } = await database.connect();\nconst migrated = await up(db, client);\nmigrated.forEach(fileName =\u003e console.log('Migrated:', fileName));\n```\n\nIf an an error occurred, the promise will reject and won't continue with the rest of the pending migrations.\n\n### `down(MongoDb, MongoClient) → Promise\u003cArray\u003cfileName\u003e\u003e`\n\nRevert (only) the last applied migration\n\n```javascript\nconst { db, client } = await database.connect();\nconst migratedDown = await down(db, client);\nmigratedDown.forEach(fileName =\u003e console.log('Migrated Down:', fileName));\n```\n\n### `status(MongoDb) → Promise\u003cArray\u003c{ fileName, appliedAt }\u003e\u003e`\n\nCheck which migrations are applied (or not.\n\n```javascript\nconst { db } = await database.connect();\nconst migrationStatus = await status(db);\nmigrationStatus.forEach(({ fileName, appliedAt }) =\u003e console.log(fileName, ':', appliedAt));\n```\n\n### `client.close() → Promise`\nClose the database connection\n\n```javascript\nconst { db, client } = await database.connect();\nawait client.close();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseppevs%2Fmigrate-mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseppevs%2Fmigrate-mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseppevs%2Fmigrate-mongo/lists"}