Node.js监听MongoDB的变化 [英] Node.js listen to MongoDB change
问题描述
Node.js是否可以侦听MongoDB集合中特定数据的更改,并在发生更改时触发事件?
Is there a way for Node.js to listen to a change in a particular data in a collection of MongoDB, and fire an event if a change happens?
推荐答案
MongoDB现在显然支持触发器和监视功能,此答案已过时.
MongoDB apparently now supports triggers and watch, this answer is outdated.
[原始] ,我相信您正在寻找数据库触发器.
[Original] I believe you are looking for a database trigger.
不幸的是,MongoDB还不支持它们,所以我认为您不能直接从数据库中监听更改.您需要设置某种通知系统(例如pub/sub),以便在收藏集发生更改时提醒感兴趣的参与者.
Unfortunately, MongoDB has no support for them yet, so I don't think you can listen for changes directly from the database. You'll need to setup some sort of notification system (e.g. pub/sub) that alerts interested parties when a collection has changed.
这篇关于Node.js监听MongoDB的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!