3

简短的问题:

如果集合中的某些内容发生更改,MongoDB 可以联系应用程序吗?某种触发器会向应用程序发出某些字段已更改或添加或类似的信号?

4

2 回答 2

2

If you can leverage the spring-data-mongodb then you can take advantage of its implicit support of events to meet your requirements.

  • onBeforeConvert - called in MongoTemplate insert, insertList and save operations before the object is converted to a DBObject using a MongoConveter.
  • onBeforeSave - called in MongoTemplate insert, insertList and save operations before inserting/saving the DBObject in the database.
  • onAfterSave - called in MongoTemplate insert, insertList and save operations after inserting/saving the DBObject in the database.
  • onAfterLoad - called in MongoTempnlate find, findAndRemove, findOne and getCollection methods after the DBObject is retrieved from the database.
  • onAfterConvert - called in MongoTempnlate find, findAndRemove, findOne and getCollection methods after the DBObject retrieved from the database was converted to a POJO.
于 2013-05-29T17:46:37.287 回答
1

不,没有回调机制。

最好 a) 轮询文档以获取应用程序的更改,b) 使用消息队列(例如 RabbitMQ)将更改数据的应用程序的更改发布给想要知道数据何时更改的订阅者。一个复杂的解决方案可能是 c) 跟踪 oplog,请参阅MongoConnector。您的 MongoDB 必须是副本集的一部分才能正常工作。

于 2013-05-29T17:01:31.780 回答