CouchDB - trigger code when creating or updating document

前端 未结 1 770
囚心锁ツ
囚心锁ツ 2021-02-04 07:01

I have a page which store data in CouchDB. The page accesses the database directly via javascript, so not much of the logic is hidden from the browser. When creating a new docum

相关标签:
1条回答
  • 2021-02-04 07:32

    You have a couple of options.

    First, see this question about CouchDB update functions. Update functions receive a request from the browser and can modify them in any way before finally storing them in CouchDB. For example, some people use them to automatically add a timestamp. Also see the wiki page on CouchDB document update handlers.

    Another option is to receive CouchDB change notifications. In this case, a separate program (either your own browser, or even better, a standalone program that you run) can query CouchDB for _changes. CouchDB will notify this program after the document is saved. Next, the program can fetch the document and then store any new revisions that are necessary.

    To me, it sounds like you should try the _update function first.

    0 讨论(0)
提交回复
热议问题