Triggers (or something similar) in MongoDB?

僤鯓⒐⒋嵵緔 提交于 2020-01-06 08:26:43

问题


Supposed I have a MongoDB, and I am storing data in it.

Is there any possibility to get triggered by MongoDB when data is inserted, updated or deleted? I know that there are tailable cursors, but they only work with capped collections.

Anything else?

Basically, is there some kind of "event" in the JavaScript API I could listen to?


回答1:


MongoDB does not have a concept of "triggers" and instead defers to you to work your own API to handle the tasks you typically associate with SQL Database triggers. The general premise is that the typical tasks of updating related collections and other such things are best handled by changing your schema design approach to include embedded lists and documents within the documents you are dealing with.

Beyond that the design preference is that you wrap your "trigger" logic into your own API from the program's point of view and give that control of such functions.

In the event that you really need to hook into every update/insert/delete you can look at tracking the oplog which is a special capped collection containing all operations from all sources processing on your MongoDB.



来源:https://stackoverflow.com/questions/21424852/triggers-or-something-similar-in-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!