Skip to content Skip to sidebar Skip to footer

Triggers (or Something Similar) In Mongodb?

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 tailab

Solution 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.

Post a Comment for "Triggers (or Something Similar) In Mongodb?"