1

I am aware that with a combination of capped collections and tailable cursors Mongo clients can subscribe to additions to the collection. This however introduces a few limitations:

  • When the collection is full, the oldest members are removed.
  • Existing members cannot be changed if they are not the same size. Cannot change the size of a document in a capped collection

Is there something more generic (such as RDBMS triggers) I can employ to listen to changes of all sorts happening to a Mongo collection?

Martin Cowie
  • 2,788
  • 7
  • 38
  • 74
  • 1
    Well there is, but it's too broad to describe here. You can only really "tail" a capped collection, but MongoDB has a special "capped collection" which is the [`oplog`](https://docs.mongodb.org/manual/core/replica-set-oplog/). So even if you only have one node, you still start it with replica set options and then just tail the oplog. Every operation that could write something is written there. This is actually how "replication" works in MongoDB. By tailing the `oplog`. – Neil Lunn Apr 23 '16 at 00:40
  • @NeilLunn - many thanks for your direction. I have something working now. However given `rs.oplog` is finite & circular, and may not contain all CRUD operations to replay/rebuild a collection I shall need to first dump my target collection `X`, then listen for updates in `rs.oplog` added after the last update to `X`. Can you say how I might get the last update timestamp from collection `X`? – Martin Cowie Apr 25 '16 at 16:38

0 Answers0