awildeep
awildeep

Reputation: 115

Detecting new data in a replicated MongoDB slave

Background: I have a very specific use case where I have an existing MongoDB that I need to interact with via reads, but I have to ensure that the data can never be modified. However I also need to trigger some form of event when new data comes in so I can do post processing on it.

The current plan is to use replication to get the data onto a slave for the read processing. However for my purposes I only care about new data in various document stores. Part of the issue is that I can not modify the existing MongoDB and not all the data is timestamped, so there is no incremental way to handle this that I can think of.

Question: Is it possible to fire an event from a slave that would tell me I have new data and what it is? I will only have access to the slave DB, as the master will be locked.

I may have some limited ability to change the master DB, but I can not expect to change the document structure at all.

Upvotes: 0

Views: 104

Answers (1)

Bernie Hackett
Bernie Hackett

Reputation: 8909

Instead of using a master/slave configuration you could instead use a replica set with a priority 0 secondary (so that it can never become primary).

You can tail the oplog on that secondary looking for insert operations.

Upvotes: 2

Related Questions