【问题标题】:Best way to monitor updates to a single mongo record from express从 express 监控单个 mongo 记录更新的最佳方法
【发布时间】:2017-01-14 15:54:47
【问题描述】:

我在 mongo 中有一个像这样的单行的审计集合。

{ total: 100, successes: 95, failures: 5}

我想使用socket.io 将其流式传输到 UI。我可以用这样的 mongo 集合来做到这一点。

const Audit = require('../models/audit'); // Mongoose Model

module.exports = function(app){

    const http = require('http').Server(app);
    const io = require('socket.io')(http);

    Audit.find().tailable().cursor()
        .on('data', function(doc) {
            console.log(doc);
            io.emit('audit', doc); // push to subscribed clients
        });
};

但是这似乎只支持插入。当我想监视对单行的更改时,我该怎么做?

【问题讨论】:

  • 您要检查集合中是否有任何文档更新
  • “匹配检查”?这是mongo的功能吗?不清楚你的意思。
  • 更新了我的评论。我真正的意思是,当任何行(mongodb 中的文档)更新时,你应该知道
  • 好吧,我尝试在 mongo 中更新记录,但从未触发过 .on('data' 函数。

标签: node.js mongodb mongoose


【解决方案1】:

您是否尝试过使用awaitDatatailable 标志设置光标?请参阅 MongoDBs Node.JS 驱动程序API Reference

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-17
    • 2021-08-22
    • 2019-06-16
    • 2011-06-30
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    相关资源
    最近更新 更多