mongoimporter
Import multiple files into mongo DB. The existing mongoimport binary is great, but this is a flexible library built for programmatic use. Currently supported filetypes: csv, json.
This library can import multiple files or an entire directory at once. If importing the entire directory, it will only import files in that directory (not subdirectories).
The destination collection names can either be explicitly stated or inferred from each filename using the useFilename option. See test/index.js for examples.
Examples
- Importing multiple files (mixed filetypes, csv or json) into mongodb:
/* Requires */const MongoImporter = /* Instantiate the mongoImporter */const mongoImporter = dbName: 'test' // can also specify dbHost and/or dbPort options here. If none specified, // mongo defaults will be used; 127.0.0.1:27017 mongoImporter
- Import a directory into mongodb. Suppose the directory "datasets" consists of the files from example 1. Then the code would be simplified to this:
/* Requires */const MongoImporter = /* Instantiate the mongoImporter */const mongoImporter = dbName: 'test' var dir = 'datasets'; mongoImporter;
(This is still in it's early stage...Tests pass and this code works, but patience requested for more advanced tasks.)