Is there any way to observe each collection
(or even one) in mongoDB
? Now I think about timer to check document number or last Id, but maybe there is some possibility to implement mechanism like newDocumentAddedEvent
?
There are no triggers in MongoDB (yet?), but if you're running a replica set (as you should), your app can pretend to be a catching-up secondary, tail the oplog collection and get information about new inserts/updates.
This is a very efficient approach (mongodb itself uses it for the replication).
来源:https://stackoverflow.com/questions/10754000/how-to-see-any-changes-new-row-in-mongodb