Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get informed about mongodb collection changes?

Tags:

c#

mongodb

Is it possible to get informed if something is changed in a collection in mongodb? For example some new document is added to the collection. Is it possible to be subscribed to these changes? Does any implementation for C# exist? Thanks.

like image 382
Oleg Dudnyk Avatar asked Nov 01 '12 07:11

Oleg Dudnyk


People also ask

How do I listen for changes in MongoDB?

When you run MongoDB in a Replica Set, all of the MongoDB actions are logged to an operations log (known as the oplog). The oplog is basically just a running list of the modifications made to the data. Replicas Sets function by listening to changes on this oplog and then applying the changes locally.

How does MongoDB change stream work?

Change streams allow applications to access real-time data changes without the complexity and risk of tailing the oplog. Applications can use change streams to subscribe to all data changes on a single collection, a database, or an entire deployment, and immediately react to them.

How do MongoDB collections work?

Instead of tables, a MongoDB database stores its data in collections. A collection holds one or more BSON documents. Documents are analogous to records or rows in a relational database table. Each document has one or more fields; fields are similar to the columns in a relational database table.

What is the difference between collection and database in MongoDB?

MongoDB stores data records as documents (specifically BSON documents) which are gathered together in collections. A database stores one or more collections of documents.


1 Answers

As @Sergio says, not inherently, however you can use a tailable cursor to achieve something similar:

http://blog.mongodb.org/post/29495793738/pub-sub-with-mongodb

Edit

Realised that article is a bit bare, this might be a better one: http://www.devco.net/archives/2012/08/31/using-mongodb-as-a-queue.php

like image 103
Sammaye Avatar answered Sep 21 '22 05:09

Sammaye