3.0.1 • Published 5 years ago

@rkesters/mongodump-stream v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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);
3.0.1

5 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.1

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago