I'm trying to set up a ChangeStream for data from my various MongoDB Datasources, and having a hard time figuring out exactly how to create the ChangeStream to update when new data is stored in MongoDB
var es = require('event-stream');
module.exports = function(app) {
var MyModel = app.models.MyModel;
MyModel.createChangeStream(function(err, changes) {
changes.pipe(es.stringify()).pipe(process.stdout);
});
MyModel.create({foo: 'bar'});
}
So, any quick info on how to set up a change-stream from a MongoDB API in StrongLoop?
Having this:
var es = require('event-stream');
module.exports = function(app) {
var myApp = app.models.Magnetometer;
myApp.createChangeStream(function(err, changes) {
changes.pipe(es.stringify()).pipe(process.stdout);
});
myApp.create({foo: 'bar'});
}
in my server/boot/realtime.js does indeed emit the ONE foo: “bar” message, but it would be much more helpful to know how to hook that to the MongoDB data that is changing so that it can stream that to the client. :-)
Thanks!
dg