Series: Datatables with Nodejs ,Express and Mongodb. Part1: Get a database to work with.
This series Datatables with Nodejs, Express and Mongodb shows a way to mirror data stored in mongodb collections in the frontend.
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 — https://datatables.net/
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 mlab.com.
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?
- Register at mlab.com .
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
http://media.mongodb.org/zips.json 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 ds11444.mlab.com:1444 -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.
Clap to show that you like this article .Thanks.