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 mongo-xlsx with all npm packages installed. Try it out:

var mongoXlsx = require("mongo-xlsx")

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

mongo-xlsx v1.0.12

Convert Mongo data into Excel and vice versa.



mongo-xlsx is a node.js utility module which provides tools that convert excel spreadsheets into/from MongoDB data. (MongoDB data -> Array of JSONs)

The general data conversion flow:

MongoDB -> (extract data w/MongooseModel.find) -> MongoData -> (convert w/mongoData2Xlsx) -> file.xlsx

file.xlsx -> (convert data w/xlsx2MongoData) -> MongoData -> (save to MongoDB w/ -> MongoDB


    "name" : "eddie", 
    "likes" : [ "video games", "ninjas" ] 
    "name" : "nico", 
    "likes" : [ "nyc" ], 
    "description" : { 
      "mascot" : "dog" 

converts to

eddievideo gamesninjas


Reverses the previous example (table -> json array)


Screenshots: spreedsheet <--> json

alt tag

Custom headers for writing and reading excel files:

alt tag Just define a model! Example

Quick Examples

var mongoXlsx = require('mongo-xlsx');

var data = [ { name : "Peter", lastName : "Parker", isSpider : true } , 
             { name : "Remy",  lastName : "LeBeau", powers : ["kinetic cards"] }];

/* Generate automatic model for processing (A static model should be used) */
var model = mongoXlsx.buildDynamicModel(data);

/* Generate Excel */
mongoXlsx.mongoData2Xlsx(data, model, function(err, data) {
  console.log('File saved at:', data.fullPath); 
/* Read Excel */
mongoXlsx.xlsx2MongoData("./file.xlsx", model, function(err, mongoData) {
  console.log('Mongo data:', mongoData); 
/* Read xlsx file without a model */
/* The library will use the first row the key */
var model = null;
var xlsx  = './file.xlsx';

mongoxlsx.xlsx2MongoData(xlsx, model, function(err, data) {
  [{ Name: 'Eddie', Email: 'edward@mail' }, { Name: 'Nico', Email: 'nicolas@mail' }]  


npm install mongo-xlsx




A model is used for converting Excel into Mongo data. The model allows, to have custom headers for writing and reading Excel files.

    "displayName": "User Identifier",
    "access": "_id",
    "type": "string"
    "displayName": "Main Index",
    "access": "index",
    "type": "number"
displayName : Excel header name
access : Object key
type: Data Type 

A model can be automaticly build with:


For example:

buildDynamicModel([{name:"eddie", age:40}, {name:"moe", age:19}, {name:"andrew", age:33} ])


[ { displayName: 'name', access: 'name', type: 'string' },
  { displayName: 'age', access: 'age', type: 'number' } ]  



Generates a Model for converting into/from Excel/MongoData. This can be used to create a static conversion model.

mongoData2Xlsx(monogData, mongoModel, [options], callback)

Converts MongoData into a Excel File

mongoData2XlsxMultiPage(excelDataArray, sheetNamesArray, [options], callback)

Converts an array of MongoData into a Excel file with multiple sheets

mongoData2XlsxData(mongoData, mongoModel)

Converts MongoData into Excel Data to allow merging into single Excel File

xlsx2MongoData(path, mongoModel, [options], callback)

Converts Excel File into Mongo Data. If mongoModel is null trys to use the file's header to build the JSON Otherwise the mongoModel map will be used to build the JSON

xlsxData2MongoData(excelData, mongoModel)

Converts Excel Data into Mongo Data. If mongoModel is null trys to use the file's header to build the JSON Otherwise the mongoModel map will be used to build the JSON


[Github issue] (

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