1.0.1 • Published 7 years ago

mongo-to-csv v1.0.1

Weekly downloads
128
License
MIT
Repository
github
Last release
7 years ago

mongo-to-csv Build Status

Export the mongodb collection to csv using mongoexport and nodejs

Usage

1. $ npm install mongo-to-csv --save
'use strict';
const mongotocsv = require('mongo-to-csv');
let options = {
	database: 'users', // required
	collection: 'pets', // required
	fields: ['name','cost'], // required
	output: './output/pets.csv', // required
	allValidOptions: '-q \'{ "name": "cat" }\'' // optional
};
mongotocsv.export(options, function (err, success) {
	console.log(err);
	console.log(success);
});

This libaray uses the mongoexportcommand provided by mongodb and execute command through nodejs child_process

you can pass all the available options of mongoexport command here through allValidOptions property.

Run test

  1. clone the repo
$ git cone https://github.com/yasharma/mongo-to-csv.git
  1. cd mongo-to-csv

  2. npm install

  3. npm test