Series: Datatables with Nodejs ,Express and Mongodb. Part1: Get a database to work with.

Deepika Gunda
2 min readMay 8, 2018


This series Datatables with Nodejs, Express and Mongodb shows a way to mirror data stored in mongodb collections in the frontend.

“Binders and boxes on shelves in a large archive” by Samuel Zeller on Unsplash

Why datatables ? Datatables convert regular HTML tables to more interactive tables with very less coding. It can help in adding ordering of columns, search box, paging of results ,styling and a lot more .

For those considering to use data from databases ,datatables library provides a way to interact with backend ,redraw the table etc.

In most websites , we would need registration ,login , showing data from tables/collections ,search of data,updating and deletion of data. So a major part of website work will be done by learning this simple tool/library.

We will be using Datatables library from —

For this series ,we want some data to be shown in datatables .For that we are going to use a hosted database of mongodb -which is provided by

What is mlab ?

mLab is the leading Database-as-a-Service for MongoDB, powering over half a million deployments worldwide.

How to create a sample collection in mlab?

  1. Register at .

2. After registration ,click on create new and choose plan type as ‘SANDBOX’ and choose any AWS region and continue to give a database name.

3. The database will be ready in a few seconds.

4.Once done ,double click on it and you will be able to create a user.

5.After user is created,click on collections and create new.

6.create a collection with “zipcodes” name.

7.Now I want to import sample data for this collection .I found sample data for all the American states zipcodes at in the JSON format.

Now I want to get this data in my zipcodes collection .

To do so , in the free tier ,there are no migration tool provided. I had to install mongodb on my local PC and use the mongoshell to run the following command.

‘/c/Program Files/MongoDB/Server/3.6/bin/mongoimport.exe’ -h -d country -c zipcodes -u root -p password — file /c/zips.json

The above command is customized from the sample commands provided by mlab in the Tools section .You need to use the username and password you had provided for the user you created .

Thats it ,we now have good data for representing in the datatable.

For the complete code -download from here.

If you like this article might be interested in

  1. Github style contribution graph
  2. How to create Sample data in mongodb .
  3. All about photo uploads in Node.js
  4. Create small webapps in few hours
  5. Visual representation of data in webapp

Clap to show that you like this article /Follow me to hear more interesting articles.



Deepika Gunda

I am a Software Engineer n Tech Enthusiast . You will see me publishing articles on Javascript, NodeJS and misc.