# @tresmo/mongodb-copy

> copy a source database into a emptied destination database.

Latest version **3.1.0** (published 2020-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tresmo/mongodb-copy
pnpm add @tresmo/mongodb-copy
yarn add @tresmo/mongodb-copy
bun add @tresmo/mongodb-copy
```

Provides the commands `mongodump`, `mongodb-copy`, `mongorestore`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2020-09-04 |
| First published | 2016-08-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 20.3 MB |
| Known vulnerabilities | 0 (+6 in 3 direct dependencies) |
| Install scripts | yes |
| Maintainers | tresmo |

## Links

- npm: https://www.npmjs.com/package/@tresmo/mongodb-copy
- npm.io page: https://npm.io/package/@tresmo/mongodb-copy

## Dependencies (12)

- [uuid](https://npm.io/package/uuid.md) ^8.3.0
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [getos](https://npm.io/package/getos.md) ^3.2.1
- [yargs](https://npm.io/package/yargs.md) ^15.4.1
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [semver](https://npm.io/package/semver.md) ^7.3.2
- [request](https://npm.io/package/request.md) ^2.88.2
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.0.1
- [md5-file](https://npm.io/package/md5-file.md) ^5.0.0
- [decompress](https://npm.io/package/decompress.md) ^4.2.1
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.6

## Recent versions

- 3.1.0 (latest) — 2020-09-04
- 3.0.13 — 2020-05-18
- 3.0.12 — 2020-03-09
- 3.0.11 — 2020-02-04
- 3.0.10 — 2019-09-16
- 3.0.9 — 2019-05-29
- 3.0.8 — 2019-05-27
- 3.0.7 — 2019-03-06
- 3.0.6 — 2019-01-28
- 3.0.5 — 2018-12-20
- 3.0.4 — 2018-12-12
- 3.0.3 — 2018-12-07
- 3.0.2 — 2018-12-06
- 3.0.1 — 2018-12-06
- 3.0.0 — 2018-12-05
- … 16 more at https://npm.io/package/@tresmo/mongodb-copy/versions

## README

# mongodb-copy

copy a source database into a emptied destination database.

##Installation
`npm install --save @tresmo/mongodb-copy`

##Usage as command
This package provides a `mongodb-copy` command as bin.
You must specify with `-s` with the source database url and with `-d` the destination database url.

###Example
Define a script in `package.json` to copy a database if environment variable `IS_REVIEW_APP` is set to `true`
```
"copydb": "if [ \"$IS_REVIEW_APP\" = \"true\" ]; then mongodb-copy -s $MONGO_EXPORT_SOURCE_URL -d $MONGODB_URI; fi"
```

##Usage as function
This package provides a function with the following parameter:
- The source database URL (required)
- The destination database url. (required)
- The string for one included collection name. (optional)
- The string of one or array of strings for excluded collection names. (optional)
- Callback if given returns (err), otherwise returns a promise.

###Examples
```
var mongodbCopy = require('@tresmo/mongodb-copy');
```
####Examples as Promise
- copy one database into backup: 
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup').then()...```
- copy the collection products from database one into backup: 
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup', 'products').then()...``` 
- copy all collections excluding products from database one into backup:
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup', null, 'products').then()...``` 
- copy all collections excluding products and customers from database one into backup:
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup', null, ['products','customers']).then()...``` 
  
####Examples with callback
- copy one database into backup: 
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup', functions(err) {...```
- copy the collection products from database one into backup: 
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup', 'products', functions(err) {...``` 
- copy all collections excluding products from database one into backup:
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup', null, 'products', functions(err) {...``` 
- copy all collections excluding products and customers from database one into backup:
  ```mongodbCopy( 'mongodb://localhost/one', 'mongodb://localhost/backup', null, ['products','customers'], functions(err) {...``` 

t

---
_Source: https://npm.io/package/@tresmo/mongodb-copy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
