This module converts your correctly formatted Excel spreadsheet to a collection in specified database in MongoDB.
Supported Excel formats are XLS/XLSX/CSV
Please have a look at the sample Excel sheets provided to have a clear view of the File. Microsoft Sample Sheet
npm install excel-to-mongoDB --save
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
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.
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.
We have got you covered! GitHub Link.
We have got you covered! GitHub Link.