This can be done by using mongoose.
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. See: https://www.npmjs.com/package/mongoose for more information and examples.
Steps:
Include mongoose:
var mongoose = require('mongoose');
Connect to database:
mongoose.connect('mongodb://mongo:27017/yourdatabasename');
Define schema:
var contactSchema = mongoose.Schema({
_id: String, //or _id: mongoose.Schema.Types.ObjectId
name: String,
email: String,
education: String,
adress: String,
mobile_no: Number
});
Define model:
var ContactModel = mongoose.model('yourcollectionname', contactSchema);
Extract data and return to webpage on call:
app.get('/getusers', function(req, res) {
ConcactMOdel.find({}}, function(err, foundData) { //empty query for all data
if(err) {
console.log(err);
return res.status(500).send();
} else {
return res.status(200).send(foundData);
}
});
});
On your webpage you can use a AJAX get request to fetch your data, then manipulate it.
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
var dataSet = JSON.parse(this.response);
//manipulate/visualise the data as you wish
}
};
xhttp.open("GET", "/getusers", true);
xhttp.send();
Hope this helps