我想在Node.js中创建一个应用程序。这个应用程式修改了文件,可以说:
{_id: xxx, text: "Hello"}
每次更改此文档时,我都想在我的node.js应用程序中执行一个功能。所以大概是这样的
$db.on('update', function(id){
console.log("There are changes in " + id)
})
如何使用Node.js做到这一点?
您正在寻找ouchdb的更改提要。每当db
您在订阅的中更新文档时,都会发送一条通知。您可以只听该通知并执行代码。
您还可以订阅特定的文档ID。请参阅POST请求中的请求选项。
另外,由于您使用的是Node js,因此建议您看一下Follow库。它使您要做的事情变得容易得多。
例子:-
var follow = require('follow');
follow({db: "<database name here>", include_docs:true},
function(error, change) {
if(!error) {
console.log(change.doc) // updated doc
console.log("Got change number " + change.seq + ": " + change.id);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句