Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including excel-to-mongodb with all npm packages installed. Try it out:

var excelToMongodb = require("excel-to-mongodb")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

excel-to-mongodb v1.5.8

A node module to covert a spreadsheet of Excel to a collection in MongoDB.

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
};

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.
}

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

excelMongo.covertToMongo(credentials, options, callback); //returns documents inserted in the database.

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.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free