【问题标题】:Meteor SmartCollection giving inconsistent resultsMeteor SmartCollection 给出不一致的结果
【发布时间】:2013-11-23 06:47:56
【问题描述】:

在浏览器 JS 控制台上,News.insert({name: 'Test'}) 导致 {{count}}0 增加到 1

在 mongo 控制台中 mrt mongodb.news.find().count() 返回 1。但是在通过 mongo 控制台 db.news.insert({name: 'TestAgain'}) 添加记录后,{{count}} 保持在 1 而在 mongo 中,现在有 2 记录。

问题:是什么导致 minimongo 和 mongodb 控制台给出不一致的结果?

如果我用Meteor.Collection 替换Meteor.SmartCollection 并重新加载页面,{{count} 现在是2。但是如果我把它改回Meteor.SmartCollection{{count}}又会变回1!!

collections/news.js

News = new Meteor.SmartCollection('news');

client/views/main.html

<template name="news">
    {{ count }}
</template>

client/views/main.js

Template.news.count = function() {
    return News.find().count();
}

将 Meteor v6.6.3 与 SmartCollection v0.3.2.2 结合使用


更新

根据 Cuberto 的建议,我已经在我的 Mongodb 服务器上启用了 Oplog。

export MONGO_URL=mongodb://192.168.1.111:27017/myDb
export OPLOG_URL=mongodb://192.168.1.111:27017/local
mrt

mongod 使用 --replSet meteor 运行,mongodb 配置了

var config = {_id: "meteor", members: [{_id: 0, host: "127.0.0.1:27017"}]}
rs.initiate(config)

mongo 中的提示也变为meteor:PRIMARY&gt; 并且db.local. 确实包含集合oplog.rs

启动流星,我们在控制台看到SmartCollection charged with MongoDB Oplog

问题: 但是,当我们尝试在浏览器 JS 控制台中执行 News.find() 时,什么都没有检索到。在mongo 客户端中执行相同的查询会返回正确的结果。从Meteor.SmartCollection 切换回Meteor.Collection 可以让网站再次运行。

我们如何解决 SmartCollection 的问题?

【问题讨论】:

    标签: javascript mongodb meteor smartcollection


    【解决方案1】:

    确保将 MongoDB 配置为使用 oplog 并设置环境变量,如下所述:

    http://meteorhacks.com/lets-scale-meteor.html

    由于智能集合删除了定期数据库轮询,您需要使用启用 oplog 的 mongodb 实例来使其识别来自外部流星的数据库更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-30
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      相关资源
      最近更新 更多