@rkesters/mongodump-stream
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

Mongo Dump Streaming Utilities

Utility to dump and restore collections of a mongo instance.

Documentation

import * as mds from '@rkesters/mongodump-stream

API

mds.slurp.binary(uri, collection)

Get a binary stream of your collection (mongodump).

mds.slurp.text(uri, collection)

Get a textual stream of your collection (mongoexport).

mds.dump.s3(key, stream, awsConf)

Write an object named key to an S3 bucket using the data in stream. awsConf must contain the properties key, secret, and bucket.

mds.dump.fs.file(stream, path)

Dump stream into path.

mds.fixture.saveFixture( name: string, collections: string[], rootPath?: string):Promise<void>

Will save the contents of the each of the collections in collections, in files named <collection name>.json. The fixture is saved in a directory with the name of name. If rootPath is defined then the fixture will be saved in that directory, if not it is saved in __dirName/__mongo_fixtures__ of the calling file.

mds.fixture.restoreFixture( name: string, rootPath?: string):Promise<void>

Will restore the collections stored in the test fixture.

Example

var mds = require('mongodump-stream');

var mongoUrl = 'mongodb://localhost:27017/YOUR-DB';
var mongoCollection = 'YOUR-COLLECTION';

var now = Date.now();

var fname = mongoCollection + '-' + now + '.bson';

var stream = mds.slurp.binary(mongoUrl, mongoCollection);

mds.dump.s3(fname, stream, {
  key: process.env.AWS_ACCESS,
  secret: process.env.AWS_SECRET,
  bucket: process.env.AWS_S3_BUCKET
}).then(/* YOUR CALLBACKS */);


//
// You could also write it to a file
//
mds.dump.fs.file(stream, fname);

Package Sidebar

Install

npm i @rkesters/mongodump-stream

Weekly Downloads

0

Version

3.0.1

License

MIT

Unpacked Size

28.5 kB

Total Files

14

Last publish

Collaborators

  • rkesters