node.jsdatabasecloudantdashdb

Call function when document is added to database?


I am working with NodeJS and Cloudant (alternatively the DashDB Warehouse if that works better). I wonder if it is possible to have a function in NodeJS that gets called each time a document has been added to the database? I have checked out indexed views but can't really understand how to do it. Does anyone have any good tips regarding this or what documentation to look at?


Solution

  • You can listen to DB _changes in Cloudant (https://console.bluemix.net/docs/services/Cloudant/api/database.html) in continous mode.

    Every document change in the Cloudant DB (create,update,delete) will be notified through this channel.

    There are different nodejs libraries you can use with this purpose. This is one example: https://www.npmjs.com/package/cloudant-follow