Write streams directly to mongoDB
- npm i mongo-stream-writer
To use this module you need to provide a valid mongoDB string, collection to write your stream to and batch size as writer arguments.
Example:
import { mwriter } from 'mongo-stream-writer'
const infile = './data/file_with_json_objects.json'
const dbString = 'mongodb://foo:bar@example.com/yourdb?authSource=yourdb'
const collection = 'foobarcollection'
const mongoStreamWriter = mwriter({ dbString: dbString, collection: collection, batchSize: 500 })
fs.createReadStream(infile)
.pipe(mongoStreamWriter)