Skip to content

very simple useful converter for mongodb data,easy quick to use.

Notifications You must be signed in to change notification settings

hpcslag/node-csv-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

node csv converter

very simple useful converter for mongodb data,easy quick to use.

###Setting up

npm install node-csv-converter

###Usage

var csv_converter = require('node-csv-converter'),
    mongojs = require('mongojs'),
    user = mongojs('User',['collections']);
  
user.collections.find(function(err,document){
    //document is array
    var converter = csv_converter();
    converter.setField(['Name','Sex','Places','Country','Phone']);
    converter.output(document,'./user.csv'); //create write stream
});

//about document:
{
  "Name":"MacTaylor",
  "Sex" : "Male",
  "Places":"HK",
  "Country":"TW",
  "Phone":"+886-76558958-8955"
}
//converter will put the right key into the field!

//about undefined or null variable:
{
  "Name":"MacTaylor",
  "Sex" : "Male",
  "Phone":"+886-76558958-8955"
}
//converter will be skipped and still put right key into the field!

###Like I said, it is so easy to use

###API setField([fieldArray])

output([objectDataArray],outputPath)

About

very simple useful converter for mongodb data,easy quick to use.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published