/excel-to-mongoDB

This module converts your correctly formatted Excel spreadsheet to a collection in the specified database in MongoDB.

Primary LanguageJavaScriptMIT LicenseMIT

excel-to-mongoDB

Build Status CircleCI

This module converts your correctly formatted Excel spreadsheet to a collection in specified database in MongoDB.

Excel Formats Supported

Supported Excel formats are XLS/XLSX/CSV

Spreadsheet Format

Please have a look at the sample Excel sheets provided to have a clear view of the File. Microsoft Sample Sheet

Installation

npm install excel-to-mongoDB --save

Testing

git clone https://github.com/ngudbhav/excel-to-mongoDB.git
cd excel-to-mongoDB/

Navigate to the folder.

cd test/
nano test.js

Now this file needs the MongoDB credentials. Provide those credentials in String format and save by pressing the following keys.

'CTRL+X'
'Y'
'Return'

Get back and test the module.

cd ..
npm test

Using

Note: Please correctly format the Excel sheet else this won't work.

var excelMongo = require('excel-to-mongoDB');

This module needs 3 arguments. The first one is the object with your credentials.

var credentials = {
	host: host,
	path: path for the excel file,
	collection: Collection name for creation,
	db: Your Database name,
	user: username for authentication. Leave blank if no authentication required,
	pass: password for authentication.
	connection: Connection Object from mongodb client. Leave blank to create a connection,
	endConnection*: 
};
  • Please note that endConnection false may not terminate the process.

The second one is an optional argument of options with default values as follows.

var options = {
	safeMode: false //Backup the db to the current working directory in dump/<db> folder.
	verbose: false //Console.log the current step processing.
	customStartEnd: false //Custom insert the row and columns rather than full excel-file. Do take care! Specifying endRow or endCol may result in insertion of redundant data.
	startRow: <required> //Valid only if customStartEnd is true. Defines the start Row of the data.
	endRow: <required> //Valid only if customStartEnd is true. Defines the end Row of the data.
	startCol: <required> //Valid only if customStartEnd is true. Defines the start Column of the data.
	endCol: <required> //Valid only if customStartEnd is true. Defines the end Column of the data.
	destination: '' // Valid only if safeMoode is true. Defines the destination of the dump file of db
}

The third argument is the callback function which should be executed.

try {
  excelMongo.covertToMongo(credentials, options, callback); //returns documents inserted in the database.
} catch(error) {
  throw error;
}

try/catch is always recommended because of the type of errors that can occur.

Error in safeMode option

Windows users need to add the following path to the environment path variable.
C:\Program Files\MongoDB\Server\<version>\bin

Right click 'This PC', head to 'properties' and 'Advanced System Settings'. From there, Click on 'Environment Variables'. Under System Variables, Search for 'PATH'. Double click the entry, click on new and add the above path.
Restart your console and you should be good to go.

Linux/Unix Users please check your installation or .bashrc.

Want to covert to MYSQL instead?

We have got you covered! GitHub Link.

Want to use the GUI instead?

We have got you covered! GitHub Link.