How to track 3rd party changes to MongoDB data
I'm not aware of a specific Reactive Extensions implementation, however the general approach (as at MongoDB 2.6) would be to create a tailable cursor on a capped collection -- the same approach taken in the German blog post you referenced.
With a tailable cursor on the replication oplog you will get a stream of changes across all databases that you can filter by namespace and operation (insert, delete, update) as appropriate.
What if I'm not using a replica set?
While an oplog is normally only created for the purposes of replication, if you have a standalone MongoDB server you can also run it as a single node replica set with the sole benefit being the oplog.
By default, the oplog size on 64-bit systems (excepting OS X) will be 5% of free disk space. You can use the oplogSize
configuration parameter to specify a different oplog size. If you don't intend to use replication, you can probably reduce the oplog size to something more suitable for your change notification. If you're not sure on an appropriate size, I would leave at the default and later follow the tutorial to Change the Oplog Size if needed.
To convert your standalone server into a single node replica set you essentially need to:
- Add a
replSet
configuration value with a unique name for your replica set (and optionally, oplogSize
if you want an initial size different from the default)
- Restart your MongoDB server so this change takes effect
- As a once off in the
mongo
shell, run rs.initiate()
to create the replica set configuration and preallocate the oplog
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…