Here is my case:
I have a MongoDB collection in Node.Js.
Let’s say three elements: a, b, c I want to insert new element as the first one and want the last one to go out.
So it would be:
d, a, b
In next iteration:
e, d, a
1.How to do that kind of insetion?
2.Is there a chance to listen for those insetions from another node.js app? Something like
collection.on('update', function() {
console.log('updated');
});
Capped collections in MongoDB preserve insertion order and discard the oldest items based on the total collection size (unfortunately measured in bytes). Seems like ideal fit for your scenario.
I believe there is no trigger/notification mechanism in MongoDB yet, only manual polling.