0

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?

Golo Roden
  • 140,679
  • 96
  • 298
  • 425
  • 1
    possible duplicate of http://stackoverflow.com/questions/9691316/how-to-listen-for-changes-to-a-mongodb-collection – xlembouras Jan 29 '14 at 07:58

1 Answers1

0

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.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317