{"id":15612493,"url":"https://github.com/euberdeveloper/mongoback","last_synced_at":"2025-06-28T08:37:19.654Z","repository":{"id":36939782,"uuid":"229480352","full_name":"euberdeveloper/mongoback","owner":"euberdeveloper","description":"The most powerful npm module to export and make backups of your MongoDB","archived":false,"fork":false,"pushed_at":"2023-03-14T23:58:20.000Z","size":16042,"stargazers_count":8,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-02T10:47:22.165Z","etag":null,"topics":["mocha","mongodb","npm","typescript"],"latest_commit_sha":null,"homepage":"https://mongoback.euber.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/euberdeveloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2019-12-21T20:36:15.000Z","updated_at":"2023-04-06T17:13:54.000Z","dependencies_parsed_at":"2024-06-21T19:15:44.105Z","dependency_job_id":null,"html_url":"https://github.com/euberdeveloper/mongoback","commit_stats":{"total_commits":175,"total_committers":5,"mean_commits":35.0,"dds":0.12,"last_synced_commit":"df28feeffb91ef95694536d69e79ce505c3a9a53"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/euberdeveloper/mongoback","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euberdeveloper%2Fmongoback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euberdeveloper%2Fmongoback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euberdeveloper%2Fmongoback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euberdeveloper%2Fmongoback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/euberdeveloper","download_url":"https://codeload.github.com/euberdeveloper/mongoback/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euberdeveloper%2Fmongoback/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262402550,"owners_count":23305657,"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","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":["mocha","mongodb","npm","typescript"],"created_at":"2024-10-03T06:43:13.973Z","updated_at":"2025-06-28T08:37:19.633Z","avatar_url":"https://github.com/euberdeveloper.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Test](https://github.com/euberdeveloper/mongoback/workflows/Test/badge.svg)\n![Lint](https://github.com/euberdeveloper/mongoback/workflows/Lint/badge.svg)\n![Build](https://github.com/euberdeveloper/mongoback/workflows/Build/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/euberdeveloper/mongoback/badge.svg?branch=master)](https://coveralls.io/github/euberdeveloper/mongoback?branch=master)\n[![Codecov Status](https://codecov.io/gh/euberdeveloper/mongoback/branch/master/graph/badge.svg)](https://codecov.io/gh/euberdeveloper/mongoback)\n[![Types](https://img.shields.io/npm/types/mongoback.svg)](https://www.npmjs.com/package/mongoback)\n[![Known Vulnerabilities](https://snyk.io/test/github/euberdeveloper/mongoback/badge.svg?targetFile=package.json)](https://snyk.io/test/github/euberdeveloper/mongoback?targetFile=package.json)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![GitHub issues](https://img.shields.io/github/issues/euberdeveloper/mongoback.svg)](https://github.com/euberdeveloper/mongoback/issues)\n[![License](https://img.shields.io/npm/l/mongoback.svg?color=blue)](https://github.com/euberdeveloper/mongoback/raw/master/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/euberdeveloper/mongoback.svg)](https://github.com/euberdeveloper/mongoback/stargazers)\n![npm](https://img.shields.io/npm/v/mongoback.svg)\n[![Maintainability](https://api.codeclimate.com/v1/badges/dc2555e4e7efdcf8bfe4/maintainability)](https://codeclimate.com/github/euberdeveloper/mongoback/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/dc2555e4e7efdcf8bfe4/test_coverage)](https://codeclimate.com/github/euberdeveloper/mongoback/test_coverage)\n\n# mongoback\nThe most powerful npm module to export your MongoDB.\n\nThis is a wrapper of the **mongoexport** tool and comes because of the annoy of typing \neverything in the command line, repeating the task for every collection to export.\n\nThis module allows to call it in a more comfortable way and to export **multiple** collections at a time. It allows you to select collections in a powerful way and saves the exported files in an organized and customizable directory.\n\n## Install\n\nBefore installing mongoback, you need the `mongoexport` installed and its path added to the envinronments variables. This should automatically happen when installing **MongoDB**.\n\nTo install mongoback as a local module:\n\n```bash\n$ npm install mongoback\n```\n\n## Usage (local module)\n\n### A first example\n\nThis tiny code (main.js):\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { all: true };\n\nawait mongoExport(options);\n```\n\nWill result in this:\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/euberdeveloper/mongoback/raw/main/docs/assets/mongoback_base_log.gif\"\u003e\n\u003c/p\u003e\n\n\nAnd the created exported directory will be like this:\n\n```\nexported\n ├─\u003e 12345\n │   ├── first.json\n │   └── second.json\n └─\u003e animals\n     ├── cats.json\n     ├── dogs.json\n     ├── horses.json\n     ├── lions.csv\n     ├── pinguins.json\n     └── tigers.csv\n```\n\n## Usage (global module)\n\nExecuting the command:\n\n`$ mongoback export`\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/euberdeveloper/mongoback/raw/master/docs/assets/mongoback_cli.gif\"\u003e\n\u003c/p\u003e\n\nExecute the help command for more informaition:\n\n`$ mongoback --help`\n\n### Features\n\nThe module allows you to:\n* Specify all the mongodb __connection__ uri and options\n* Specify in a powerful way the __collections__ to export\n* By using __RegExp__ and __functions__, export collections you do not know they exist\n* Specify in a powerful way all the __mongoexport options__ for each collection\n* Specify in a powerful way in which __path__ end with which __file name__ will every collection be saved\n* Specify the output __directory__ and its __structure__\n* Specify if and how show the function __logs__\n* Specify if an __error__ will be thrown in case not all collections can be fetched/exported\n\n### How it works\n\nThe module:\n* Checks if mongoexport is installed\n* Parses the options and, connecting to the mongodb, gets all the name of the collections that you want to export\n* By calling mongoexport, exports the collections and saves them in a directory structure customizable by the options\n* Returns an object containing information about what has been exported\n\nTo learn well to use the module, it is suggested to see the examples below before reading the API.\n\n## Examples\n\n### Specify the mongodb connection\n\n\n#### This will export all the collections in `mongodb://myhost:27017`.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    uri: 'mongodb://user:secret@myhost:27017',\n    all: true \n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections in `mongodb://myhost:8080`\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    all: true \n};\n\nawait mongoExport(options);\n```\n\n#### This will add username and password:\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    username: 'me',\n    password: 'secret',\n    auhenticationDatabase: 'administrator',\n    all: true \n};\n\nawait mongoExport(options);\n```\n\n#### This will add srv (`mongodb+srv//myhost`):\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    srv: true,\n    all: true \n};\n\nawait mongoExport(options);\n```\n\n#### This will use a replica set connection:\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: [\n        { host: 'localhost', port: 27017 },\n        { host: 'myhost': port: 23023 }\n    ],\n    replicaSetName: 'replicas',\n    all: true \n};\n\nawait mongoExport(options);\n```\n\n### Specify what is to be exported\n\n#### This will export all the collections in `mongodb://localhost:27017`:\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { all: true };\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections of database `animals`:\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: 'animals'\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the databases beginning with `test`:\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: /^test/\n};\n\nawait mongoExport(options);\n```\n\n#### This will export the `animals` database and the ones beginning with `test`:\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: ['animals', /^test/]\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the databases beginning with `test`. Every exported collection will have also the `--jsonArray` mongoexport option.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: { \n        match: /^test/, \n        jsonArray: true \n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export the `animals` database and the ones beginning with `test`. All collections exported by the animals database will have also the `--jsonArray` mongoexport option.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: [\n        /^test/,\n        { match: 'animals', jsonArray: true }\n    ]\n};\n\nawait mongoExport(options);\n```\n\n#### This will export the database `animals` and all the databases whose length is `4` \n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: [\n        'animals',\n        (db) =\u003e (db.length === 4)\n    ]\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the databases whose length is `4`, adding the `--pretty` and `--limit=5` mongoexport options to each of them. \n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: function(db) {\n        if (db.length === 4) {\n            return {\n                pretty: true,\n                limit: 5\n            };\n        }\n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections. The ones of the database `animals` will be the only one to be of type `json`. This is because the exporting options specified inside databases overwrite the general ones.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    type: 'csv',\n    fields: ['timestamp', 'name'],\n    databases: {\n        match: 'animals',\n        type: 'json'\n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections (in any database) whose name is `kebab`\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    collections: 'kebab'\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections (in any database) whose name is `kebab` or that begin with `test`\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    collections: ['kebab', /^test/]\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections whose database begins with `a` and whose name is of length greater than `5`. All these collections will have also the `--pretty` mongoexport option.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    collections: function(db, collection) {\n        if (db[0] === 'a' \u0026\u0026 collection.length \u003e 5) {\n            return {\n                pretty: true\n            };\n        }\n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections in database `animals` and all the collections beginning with `a` or `b`. All the collections have the `--pretty` option. The collections of database `animals` will have the `--jsonFormat=canonical` option. The collections beginning with `a` will have the `--jsonFormat=relaxed` option, even if they are in the database animals. This is because the collections exporting options overwrite the database ones.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    pretty: true,\n    databases: {\n        match: 'animals',\n        jsonFormat: 'canonical'\n    },\n    collections: [\n        {\n            match: /^a/,\n            jsonFormat: 'relaxed'\n        },\n        /^b/\n    ]\n};\n\nawait mongoExport(options);\n```\n\n#### This will export the collections `tiger` and the ones beginning with `c` or `C` of the database `animals`, the collections `students` and `teachers` of the database `people` and the collection `valdagno` of the database `cities`.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    collections: {\n        animals: ['tiger', /^c/i],\n        people: ['sutdents', 'teachers'],\n        cities: 'valdagno'\n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export the collections `wombats` and the ones whose name length is lower than `5` of the database `animals`.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    collections: {\n        animals: [\n            'wombats',\n            (_db, collection) =\u003e collection.length \u003c 5\n        ]\n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export the collections `tigers`, `pinguins` and `bears` of the database `animals` and the collection `students` of the database `people`. Almost all collections will have the ``--pretty` option. All the collections of `animals` will not have the `--jsonArray` option. All the collections of `animals` will have the `--pretty` option, except for `bears`. This is because the exporting options specified in a collection overwrite the ones specified in a database that overwrite the ones specified in the options.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    pretty: true,\n    collections: {\n        animals: {\n            collections: [\n                'tigers',\n                'pinguins',\n                {\n                    match: 'bears',\n                    pretty: true\n                }\n            ],\n            pretty: false,\n            jsonArray: true\n        }\n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections of the database `animals`. All the collections will have the `--jsonArray` options, except for the `tigers` and `pinguins` that will have the `--pretty` option instead. \n\nThis is because order of which the collections are exported is:\n\n* collections bound to a database\n* collections bound to no database\n* databases\n* all\n\nIf, as in this case, the collections `tigers` and `pinguins` are matched by the `databases` option but are already matched by the `collections` one, they are ignored and the exporting options in `databases` will not worth for them. \n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    databases: {\n        match: 'animals',\n        jsonArray: true\n    },\n    collections: {\n        animals: {\n            collections:  ['tigers', 'pinguins'],\n            pretty: true\n        }\n    }\n};\n\nawait mongoExport(options);\n```\n\n#### This will export the collections `tigers` and `lions` of the database `animals`, the collection `students` and all the collections beginning with `p` or `s` of the database `people` and all the collections whose database name length is greater than `6` and whose name begins with `t`. All the collections beginning with `p` or `s` of the database `people` will be exported as csv and the `students` one will also have the `--noHeaderLine` option. All the collections whose database name length is greater than `5` and whose collection name begins with `t` will have the `--skip=20` option, except for `tigers` that is already exported without that option.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    pretty: true,\n    collections: [\n        {\n            animals: ['tigers', 'lions'], \n            people: {\n                collections: [\n                    {\n                        match: 'students',\n                        noHeaderLine: true\n                    },\n                    /^p/, \n                    /^s/\n                ],\n                type: 'csv',\n                fields: 'timestamp'\n            }\n        },\n        (db, collection) =\u003e {\n            if (db.length \u003e 6 \u0026\u0026 collection[0] === 't') {\n                return { skip: 20 };\n            }\n        }\n    ]\n};\n\nawait mongoExport(options);\n```\n\n#### This seems exactly the same example of the one directly above, but its result is actually different. In this example, the collection `students` of the database `people` will not have the `--noHeaderLine` option. This is because the order of the elements of an array matters for the `mongoExport` function. I this case, the object containing `noHeaderLine` and bound to the collection `students` of the database `people` comes after the RegExp `/^s/`. Matching that RegExp, `students` will be already exported when the object containing `noHeaderLine` will be considered, hence the object will be ignored. \n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    host: 'myhost',\n    port: 8080,\n    pretty: true,\n    collections: [\n        {\n            animals: ['tigers', 'lions'], \n            people: {\n                collections: [\n                    /^p/, \n                    /^s/,\n                    {\n                        match: 'students',\n                        noHeaderLine: true\n                    }\n                ],\n                type: 'csv',\n                fields: 'timestamp'\n            }\n        },\n        (db, collection) =\u003e {\n            if (db.length \u003e 5 \u0026\u0026 collection[0] === 't') {\n                return { skip: 20 };\n            }\n        }\n    ]\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections, including even the system collections.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    systemCollections: true\n};\n\nawait mongoExport(options);\n```\n\n### Specify errors and warning options\n\n#### This will export all the collections. An error will be thrown wether it was not possible (probably for lack of permissions) to list the databases or the collections of a database. Usually, when this happens, those collections are ignored and all what could be fetched are exported.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    throwIfLackOfPermissions: true\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections. An error will be thrown wether there was an error in one of the mongoexport executions. Usually, when this happens, the error is ignored and the result code will be PARTIAL (1) instead of TOTAL (0).\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    throwIfOneFails: true\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections. A warning message is logged wether there was a lack of permissions error or a mongoexport error.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    warnIfLackOfPermissions: true,\n    warnIfOneFails: true\n};\n\nawait mongoExport(options);\n```\n\n### Specifying were will the files be saved\n\n#### This will export all the collections. The result files will be saved in the directory `./backup` and not in the path `./exported` as per default. Per default, a folder will be created for each database and for every exported collection the file name will be the collection name and location in the folder bound to its database name.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    outDir: './backup'\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections. Instead of creating a folder for each database, the collections files will be saved directly in the `backup` folder and the file name will be `database_collection.extension`.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    outType: 'flat',\n    outDir: './backup'\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections of `animals` and `people`. The files of the collections `students` and `teacher` of the database `people` will be prepended by the database name. The file of the `tigers` collection of the database `animals` will be `tigri.json`. The file of the `pinguins` collection of the database `animals` will be `pinguins.animals.json`.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    databases: [`animals`, `people`],\n    collections: {\n        animals: [\n            {\n                match: 'tigers',\n                fileName: 'tigri'\n            },\n            {\n                match: 'pinguins',\n                fileName: (db, collection, type) =\u003e `${collection}.${db}.${type}`\n            }\n        ],\n        people: {\n            collections: ['students', 'teachers'],\n            prependDbName: true\n        }\n    },\n    outDir: './backup'\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections of `animals` and `people`. The files of the collections `students` and `teacher` of database `people` will be in a path `./database/collection/collection.json`, relative to the `outDir` folder. The file of the `tigers` collection of the database `animals` will be saved in the `Desktop`.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    databases: [`animals`, `people`],\n    collections: {\n        animals: {\n            collections: 'tigers',\n            filePath: `/home/user/Desktop/tigers.json`,\n            absoultePath: true\n        },\n        people: {\n            collections: ['students', 'teachers'],\n            filePath: function(db, collection, type) {\n                return `${db}/${collection}/${collection}.${type}`;\n            }\n        }\n    },\n    outDir: './backup'\n};\n\nawait mongoExport(options);\n```\n\n### Specifying what is to be logged by the function\n\n#### This will export all the collections of the database. Instead of the default `base` log, the mongoexport commands and the mongoexport logs will be logged.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    logs: ['commands', 'mongoexport']\n};\n\nawait mongoExport(options);\n```\n\nThe log will be similar to this:\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/euberdeveloper/mongoback/raw/master/docs/assets/mongoback_mongoexport_log.gif\"\u003e\n\u003c/p\u003e\n\n#### This will export all the collections of the database. Instead of showing the mongoexport logs in the end, it will be logged in realtime.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    logs: ['commands', 'mongoexport'],\n    realtimeLog: true\n};\n\nawait mongoExport(options);\n```\n\n#### This will export all the collections of the database. Instead of the default `base` log, the fetched collections and the correctly exported collections are logged.\n\n```js\nconst { mongoExport } = require('mongoback');\nconst options = { \n    all: true,\n    logs: ['expectedCollections', 'actualCollections']\n};\n\nawait mongoExport(options);\n```\n\nThe log will be similar to this:\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/euberdeveloper/mongoback/raw/master/docs/assets/mongoback_exported_log.gif\"\u003e\n\u003c/p\u003e\n\n## API\n\nThe documentation site is: [mongoback documentation](https://mongoback.vercel.app)\n\nThe documentation for development site is: [mongoback dev documentation](https://mongoback-dev.vercel.app)\n\n### mongoExport\n\n**Syntax:**\n\n`mongoback.mongoExport(options)`\n\n**Description:**\n\nThe function to export collections from a mongodb. You can specify the mongodb collection, the collections that will be exported, how they will be exported and where. To understand well how to use it, it is recommended reading the __Examples__ above.\n\n**Parameters**:\n\n* __options__: The options object of the mongoExport function.\n\n**Options parameters:**\n\nThe Options object is the merge of other more-specific options objects, defined below.\n\n**ConnectionOptions parameters:**\n\nThe MongoDB connection options. They will define both the options of the mongoexport command and the uri/MongoClientOptions of the connection used to list databases and collections. Most of the properties are exactly the same of the mongoexport options. Some are  slightly modified to allow a more confortable usage, without changing what will be passed as a mongoexport option. The default value of the option does not corrispond with the mongoexport one. When there is a value set to false or undefined, it means that the option is not added to the mongoexport command, not that it is the default value of mongoexport. To support the old versions of mongoexport, there are also the deprecated options.\n\n* __uri__: Default value: `undefined`. The uri of the MongoDB connection. If it is specified, the options host, port, password, username, srv, authenticationMechanism, authenticationDatabase will be set to undefined and ignored.\n* __host__: Default value: `localhost`. The host of the MongoDB connection. It can be a string or an array of ReplicaSet, objects with host and port keys. The property differs from the mongoexport one in which also an array of replica sets can be passed.\n* __port__: Default value: `27017`. The port of the MongoDB connection.\n* __username__: Default value: `undefined`. The username of the MongoDB connection.\n* __password__: Default value: `undefined`. The password of the MongoDB connection.\n* __authenticationDatabase__: Default value: `undefined`. The authenticationDatabase of the MongoDB connection.\n* __authenticationMechanism__: Default value: `undefined`. The authenticationMechanism of the MongoDB connection.\n* __srv__: Default value: `false`. If the connection  If the MongoDB connection uri is an srv. This property is not  present in the mongoexport options, where the \"+srv\" can be added manually in the host option.\n* __replicaSetName__: Default value: `undefined`. The replicaSetName of the MongoDB connection. This property is not present in the mongoexport options, where the replica set name is passed in the uri options or in the host option.\n* __ssl__: Default value: `false`. If the MongoDB connection uses ssl or tls.\n* __sslCAFile__: Default value: `undefined`. Specifies the .pem file that contains both the TLS/SSL certificate and key.\n* __sslPEMKeyFile__: Default value: `undefined`. Specify the file name of the .pem file using relative or absolute paths.\n* __sslPEMKeyPassword__: Default value: `undefined`. Specifies the password to de-crypt the certificate-key file (i.e. --sslPEMKeyFile). Use the --sslPEMKeyPassword option only if the certificate-key file is encrypted. In all cases, the mongoexport will redact the password from all logging and reporting output.\n* __sslCRLFile__: Default value: `undefined`. Specifies the .pem file that contains the Certificate Revocation List. Specify the file name of the .pem file using relative or absolute paths.\n* __sslFIPSMode__: Default value: `false`. Directs the mongoexport to use the FIPS mode of the installed OpenSSL library. Your system must have a FIPS compliant OpenSSL library to use the --sslFIPSMode option. NB: Deprecated option of mongoexport.\n* __sslAllowInvalidCertificates__: Default value: `false`. Bypasses the validation checks for server certificates and allows the use of invalid certificates. When using the allowInvalidCertificates setting, MongoDB logs as a warning the use of the invalid certificate.\n* __sslAllowInvalidHostnames__: Default value: `false`. Disables the validation of the hostnames in TLS/SSL certificates. Allows mongoexport to connect to MongoDB instances even if the hostname in their certificates do not match the specified hostname.\n* __gssapiServiceName__: Default value: `undefined`. Specify the name of the service using GSSAPI/Kerberos. Only required if the service does not use the default name of mongodb.\n* __gssapiHostName__: Default value: `undefined`. Specify the hostname of a service using GSSAPI/Kerberos. Only required  if the hostname of a machine does not match the hostname resolved by DNS.\n* __slaveOk__: Default value: `false`. Sets the Read Preference to nearest, allowing mongoexport to read data from secondary replica set members. NB: Deprecated option of mongoexport\n* __readPreference__: Default value: `undefined`. Specify the read preference for mongoexport. It can be a string such as 'primary' or 'secondary' or an object. If you want to pass the json object as a string, you must manually include it in apixes.\n* __journal__: Default value: `false`. Allows mongoexport operations to access the durability journal to ensure that the export is in a valid state. This option is only relevant when specifying the --dbpath option. NB: Deprecated option of mongoexport\n* __ipv6__: Default value: `false`. Enables IPv6 support that allows mongoexport to connect to the MongoDB instance using an IPv6 network. All MongoDB programs and processes, including mongoexport, disable IPv6 support by default. NB: Deprecated option of mongoexport\n* __dbpath__: Default value: `undefined`. Specifies the directory of the MongoDB data files. If used, the --dbpath option enables mongoexport to attach directly to local data files and insert the data without the mongod. To run with --dbpath, mongoexport needs to lock access to the data directory: as a result, no mongod can access the same path while the process runs. NB: Deprecated option of mongoexport\n* __directoryperdb__: Default value: `false`. Use the --directoryperdb in conjunction with the corresponding option to mongod, which allows mongoexport to export data from MongoDB instances that have every database’s files saved in discrete directories on the disk. This option is only relevant when specifying the --dbpath option. NB: Deprecated option of mongoexport.\n\n**ExportedOptions parameters:**\n\nThe exported options interface. It contains the options about what should be exported and what to do if it is not exported correctly.\n\n* __all__: Default value: `false`. If all the collections of every database will be exported.\n* __databases__: Default value: `[]`. The databases that will be exported. All the collections of a database will be exported. Eventual exporting options passed to this option will overwrite the default ones.\n* __collections__: Default value: `[]`. The collections that will be exported. Eventual exporting options passed to this option will overwrite the default ones and the ones in the \"database\" option.\n* __systemCollections__: Default value: `false`. If also system collections will be exported.\n* __throwIfLackOfPermissions__: Default value: `false`. If for permissions causes there is an error while listing databases or collections of the MongoDB, an error will be thrown. If the value is false, the databases and collections that cannot be listed will be ignored and not be exported. NB: Actually all the errors that happen while listing databases or collections, not only the permission ones, will be thrown.\n* __warnIfLackOfPermissions__: Default value: `false`. If for permissions causes there is an error while listing databases or collections of the MongoDB, a warning message will be logged. NB: Actually all the errors that happen while listing databases or collections, not only the permission ones, will be warned.\n* __throwIfOneFails__: Default value: `false`. If the mongoexport of a collection fails, an error will be thrown. If the  value is false, the result of the function will have code PARTIAL(= 1), specifying that not all the expected collections were exported.\n* __warnIfOneFails__: Default value: `false`. If the mongoexport of a collection fails, a warning will be logged.\n\n**ExportingOptions parameters:**\n\nThe options about how the collections will be exported. They will define both the options of the mongoexport command and others not regarding it. See the mongoexport official documentation to further information. It is divided in `ExtendedExportingOptions` (not regarding mongoexport) and `StandardExportingOptions` (regarding mongoexport).\n\n**ExtendedExportingOptions parameters**\n\nOptions that specify how will the options be exported and are not about the mongoexport options.\n\n* __prependDbName__: Default value: `undefined`. If the file name will be prepended by the database of the collection. The format is: \"database_filename.extension\". When undefined, if the outType is 'deep' the file name is not prepended while if the outType is 'flat' it is prepended\n* __fileName__: Default value: `undefined`. A string or a function returning the name of the file of the exported collection.\n* __filePath__: Default value: `undefined`. A string or a function returning the path of the file of the exported collection.\n* __absolutePath__: Default value: `false`. If the filePath value is absolute and not relative to the outDir option.\n\n**StandardExportingOptions parameters**\n\nThe exporting options regarding the mongoexport command. Most of the properties are exactly the same of the mongoexport options. Some are   slightly modified to allow a more confortable usage, without changing what will  be passed as a mongoexport option. The default value of the option does not corrispond with the mongoexport one. When there is a value set to false or undefined, it means that  the option is not added to the mongoexport command, not that it is the default value of  mongoexport.    To support the old versions of mongoexport, there are also the deprecated options. See the mongoexport official documentation to further information.\n\n* __quiet__: Default value: `false`. Runs mongoexport in a quiet mode that attempts to limit the amount of output.\n* __verbose__: Default value: `false`. Increases the amount of internal reporting returned on standard output or in  log files. Increase the verbosity with the -v form by including the option  multiple times, (e.g. -vvvvv.) If the value is true, the option '--verbose' will be added. If it is a number, it will be the number of v that will be put in the command. (e.g. 3 gives -vvv).\n* __type__: Default value: `undefined`. Accepted values: `\"json\"` or `\"csv\"`. Specifies the file type to export. Specify csv for CSV format or json for JSON format. If you specify csv, then you must also use either the --fields or the  --fieldFile option to declare the fields to export from the collection.\n* __jsonFormat__: Default value: `undefined`. Accepted values: `\"realaxed\"` or `\"canonical\"`. Modifies the output to use either canonical or relaxed mode of the MongoDB Extended JSON (v2) format.\n* __jsonArray__: Default value: `false`. Modifies the output of mongoexport to write the entire contents of the export  as a single JSON array. By default mongoexport writes data using one JSON  document for every MongoDB document.\n* __pretty__: Default value: `false`. Outputs documents in a pretty-printed format JSON.\n* __query__: Default value: `undefined`. Provides a query as a JSON document (enclosed in quotes) to return matching documents in the export. You must enclose the query document in single  quotes ('{ ... }') to ensure that it does not interact with your shell environment. Starting in MongoDB 4.2, the query must be in Extended JSON v2 format (either relaxed or canonical/strict mode), including enclosing the field names and operators in quotes. You can pass the argument either as a string (it will automatically be included in apixes) or as an object.\n* __fields__: Default value: `undefined`. Specifies a field or fields to include in the export. Use a comma separated list of fields to specify multiple fields. If any of your field names include white space, use quotation marks to enclose the field list. For example, if you wished to export two fields, phone and user number, you would specify --fields \"phone,user number\". For csv output formats, mongoexport includes only the specified field(s), and the specified field(s) can be a field within a sub-document. For JSON output formats, mongoexport includes only the specified field(s) and the _id field, and if the specified field(s) is a field within a sub-document, the mongoexport includes the sub-document with all its fields, not just the specified field within the document. You can pass either a string ora an array of strings. The fields are automatically included in quotes to support whitespaces.\n* __fieldFile__: Default value: `undefined`. An alternative to --fields. The --fieldFile option allows you to specify   in a file the field or fields to include in the export and is only valid   with the --type option with value csv. The file must have only one field per line, and the line(s) must end with the LF character (0x0A).\n* __noHeaderLine__: Default value: `false`. By default, mongoexport includes the exported field names as the first line in a CSV output. --noHeaderLine directs mongoexport to export the data without the list of field names. --noHeaderLine is only valid with the --type option with value csv.\n* __skip__: Default value: `undefined`. Use --skip to control where mongoexport begins exporting documents. See skip() for information about the underlying operation.\n* __limit__: Default value: `undefined`. Specifies a maximum number of documents to include in the export. See limit() for information about the underlying operation.\n* __sort__: Default value: `undefined`. Specifies an ordering for exported results. If an index does  not exist that can support the sort operation, the results  must be less than 32 megabytes.  You can pass the argument either as a string (it will automatically be included in apixes) or as an object.\n* __forceTableScan__: Default value: `false`. Forces mongoexport to scan the data store directly instead of traversing the _id field index. Use --forceTableScan to skip the index.\n\n**LogOptions parameters:**\n\nThe options about what will be logged during the function execution\n\n* __silent__: Default value: `false`. If nothing will be logged.\n* __log__: Default value: `['base']`. The log modes. If there is more than a mode, they must be specified in an array.Possible values: `base`: During exporting, the databases and collections are shown with a spinner, `command`: Logs the mongoexport command, `mongoexport`: Logs the mongoexport log, `expectedCollections`: Logs the object containing the collections expected to be exported, `actualCollections`: Logs the object containing the collections that have actually been exported\n* __realtimeLog__: Default value: `false`. If the `mongoexport` log is specified, it will show the actual log generated by mongoexport under the hood. If this option is true, this log will be shown in realtime, during the exporting operation. If it is false, it will be shown in the end of the exporting operation.\n\n**OutOptions parameters:**\n\nThe options about the output location and the result of the function\n\n* __outDir__: Default value: `'./exported'`. The path were the exported collections will be saved.\n* __outType__: Default value: `'deep'`. The type of the saving location. It can be: 'deep': A folder will be created for each database. Each folder contains the  exported collections of that database with the collection name as file name 'flat': No folder will be created for each database. A file whose name is the  exported collection name prepended by its database name (if prependDBName is not false)  will be created for each exported collection\n* __detailedResult__: Default value: `false`. If the result will contain also the exporting options of the expected/actual collections.\n\n## Project structure\n\nMade with **[dree](https://www.npmjs.com/package/dree)**.\n\n```\nmongoback\n ├─\u003e source\n │ ├─\u003e bin\n │   ├─\u003e lib\n │   │   ├─\u003e errors\n │   │   ├── index.ts\n │   │   ├─\u003e interfaces\n │   │   └─\u003e utils\n │   └── tsconfig.json\n ├─\u003e test\n │   ├─\u003e complete\n │   ├─\u003e getCommand\n │   ├─\u003e getMongoConnection\n │   ├─\u003e mock\n │   ├── test.ts\n │   ├── tsconfig.json\n │   └─\u003e utils\n ├─\u003e dist\n │   ├─\u003e source\n │   └─\u003e test\n ├─\u003e docs\n │   ├─\u003e assets\n │   └─\u003e tree\n │       ├── dree.config.json\n │       └── tree.txt\n ├── package-lock.json\n ├── package.json\n └── .eslintrc.js\n```\n\n## Build\n\nTo build the module make sure you have Typescript installed or install the dev dependencies. After this, run:\n\n```bash\n$ npm run transpile\n```\n\nThe `source` folder will be compiled in the `dist` folder.\n\n## Dev\n\nMake sure you have the dev dependencies installed.\n\nTo lint the code go to the package root in your CLI and run\n\n```bash\n$ npm run lint\n```\n\nTo run tests go to the package root in your CLI and run\n\n```bash\n$ npm run db:populate\n$ npm test\n```\n\n**Note: Running tests will delete permanently your MongoDB data. Do not do it if you have important data on it**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuberdeveloper%2Fmongoback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feuberdeveloper%2Fmongoback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuberdeveloper%2Fmongoback/lists"}