I am trying to setup MongooseJS to push out the whole collection (or just the newest item) when new documents are inserted into the collection by another application.
I assumed QueryStream was the way to go.
However, when I start my simple application, it reads out the collection once, and closes it.
When I insert a new document nothing happens (assuming the connection is no longer open and looking for new results...?)
var Orders = db.model('orders', OrderSchema);
var stream = Orders.find().stream();
stream.on('data', function(doc){
console.log('New item!');
console.log(doc);
}).on('error', function (error){
console.log(error);
}).on('close', function () {
console.log('closed');
});
Immediately prints all the items that are currently in the orders collection, and than prints "closed". Shouldn't the "Stream" remain open printing new data when the collection changes?
What am I not understanding about the MongooseJS QueryStream?
Ps. my goal is to eventually emit an updated collection via socket.io as demonstrated here: Mongoose stream return few results first time