MongooseToCsv
Export mongoose queries in csv format. The headers will be, the properties of your mongoose schema, while
giving you the ability to transform and order them as you wish.
$ npm install mongoose-to-csv
MongooseToCsv([options])
- model Mongoose Model, See model method
- filename String, See filename method
- exclude String, See exclude method
- data Array, See data method
- order String, See order method
var mongooseToCsv = require('mongoose-to-csv');
mongooseToCsv()
var mongooseToCsv = new require('mongoose-to-csv').MongooseToCsv();
Methods
-
MongooseToCsv#model(model)
* model Mongoose Model
-
MongooseToCsv#data(data)
* data Array Mongoose query
-
MongooseToCsv#filename(filename)
* filename String Csv filename
-
MongooseToCsv#order(order)
* order String Space separated list of properties of the schema, this will be the order for the headers of the csv files
-
MongooseToCsv#exclude(excludes)
* excludes String Space separated list of properties to eclude from the csv file.
-
MongooseToCsv#use(transformer)
* transformer Object|Function
If the `transformer` is an Object, it should be a one to one correspondence
Example
```js
// property : header
{
'firstname': 'User FirstName'
}
```
If function, then it should be a one to all transformative function, that takes a single property as an argument.
-
MongooseToCsv#run()
* returns a WritableStream
Example
MyModel.find({}, function (err, doc) {
mongooseToCsv()
.filename('export.csv')
.model(MyModel)
.exclude('_id')
.order('name email phone street')
.use(function (prop) {
return (prop.slice(0, 1).toUpperCase() + prop.slice(1))
})
.run()
.on('finish', function () {
});
});