mongo-dump-collection
v1.1.1
Published
A Node function to connect into MongoDB, get documents from collection by name and save the content to CSV file. Store your sensitive informations in .env or inject from pipeline are good pratices and this way i did. ### Install ```sh npm i mongo-dump-col
Downloads
4
Maintainers
Readme
Dump mongo collection to CSV
A Node function to connect into MongoDB, get documents from collection by name and save the content to CSV file. Store your sensitive informations in .env or inject from pipeline are good pratices and this way i did.
Install
npm i mongo-dump-collection
Function
The exported function returns nothing but it`s a Promise and you should append .then or use async/await to treat exceptions.
dumpCollectionAsCSV(options: Object) => void
Params
mongoConnectionString and collectionName are required params, outputPath is optional and has './dump.csv' as default value.
const options = {
mongoConnectionString: 'Your mongoDB connection string',
collectionName: 'Collection`s name',
outputPath: 'Path to save output file'
}
Example
You can find the same code in example.js
require('dotenv').config()
const dumpCollectionAsCSV = require('./index')
const mongoConnectionString = process.env.MONGO_URL
const collectionName = process.env.COLLECTION_NAME
const options = { mongoConnectionString, collectionName }
dumpCollectionAsCSV(options)