Any tutorial on how to connect from mongodB from AWS
I have MongodB driver and this is initial read in from AWS
MongoClient = require('mongodb').MongoClient, assert = require('assert');
var url = 'mongodb://ec2-XX-XX-XXX-XX.us-west-2.compute.amazonaws.com:27017/mystoredata';
MongoClient.connect(url, function (err, db) {
assert.equal(null, err);
console.log("Connected successfully to energy server!");
findDocuments(db, function () {
db.close();
});
});
var findDocuments = function (db, callback) {
var collection = db.collection('myenergydata');
console.log('This is collection : ', collection);
var myCount = db.collection('myenergydata').count();
console.log('Counted number of documents : ', myCount);
// Find some documents
collection.find({}).toArray(function (err, chartData) {
assert.equal(err, null);
console.log("Found the following records");
console.log(chartData);
console.log('Type of doc is : ', typeof(chartData)); //Type of doc is : object
console.log('Object 0 energy is :', chartData[0].energy); //16
console.log('Object 0 time is :', chartData[0].time); // 06/08/2015 10:00
console.log('Object 0 time is :', chartData[1].time); //06/08/2015 10:30
callback(chartData);
});
};
which is 30 mins data of the format
{
"_id" : ObjectId("57d9209236b7c31958782bd2"),
"time" : "01/08/2015 01:30",
"energy" : 29,
"created_date" : ISODate("2016-09-14T00:00:00Z")
}
{
"_id" : ObjectId("57d9209236b7c31958782bd3"),
"time" : "01/08/2015 02:00",
"energy" : 28,
"created_date" : ISODate("2016-09-14T00:00:00Z")
}
and plot.js to update real time as new data comes in?