KRL
KRL

Reputation: 125

stream realtime sensor data into rethinkdb

I have connected to a sensor json feed with jquery and am currently graphing it realtime with smoothie charts. I am thinking to pipe this stream into a moongodb ot rethinkdb table for a rolling 30 days ttl for reporting, mapping, and to just stream to smoothie. Does anyone have any sample code that I could use as a template for getting the json stream into nosql? The TTL option is a great idea and using dynamodb this was something that I was able to set, but understand there are some limitations to rethink in this regards, so for the time being, I am just trying to stream the data into a table. Hopefully someone has some good examples of realtime json streams into nosql db's

this gets it out of mongodb and into smoothie, but first i need to get the json feed into mongo

https://blog.codecentric.de/en/2014/01/realtime-analytics-mongodb-nodejs-smoothiecharts/

Upvotes: 0

Views: 346

Answers (1)

Atish
Atish

Reputation: 4435

MongoDB 3.6 has a brand new feature called change stream that allows you to listen changes happening on your collections in real time.

The sample code to listen selected changes happening on your collection is below:

var MongoClient = require('mongodb').MongoClient
, assert = require('assert');
MongoClient.connect("mongodb://172.16.0.110:27017/myproject?readConcern=majority").then(function(client){
  var db = client.db('myproject')
  var changeStreams =  db.collection('documents').watch()
  changeStreams.on('change', function(change){
    console.log(change)  
  })

}) If you are using node.js, you need to use following node module to get it working:

"dependencies": {
    "mongodb": "mongodb/node-mongodb-native#3.0.0"
  }

Upvotes: 1

Related Questions