【问题标题】:Meteor Collection Says It's Empty流星收藏说它是空的
【发布时间】:2015-08-07 09:29:12
【问题描述】:

我早些时候发布了这个 (Shared Collection Between Client and Server Meteor),我不确定它是否完全解决了,但我相信又出现了另一个问题。

在我的client.js 文件中执行console.log(Streams.find().fetch()); 时,结果为[]。但是当我使用meteor mongo 来检查数据库(db.Streams.find().forEach(printjson))时,会出现三个不同的对象。

发生了什么事?

lib/streams.js

Streams = new Meteor.Collection("streams");

server/server.js

Meteor.publish("streams", function () {
  return Streams.find();
});

client/client.js

if(Meteor.isClient){
    Meteor.subscribe("streams");
    Template.body.helpers ({
      streams: function() {
        console.log(Streams.find().fetch());
        return Streams.find();
      }
   });
}

【问题讨论】:

  • 您确实需要在此处发布您的确切代码,因为如果我们不知道您在做什么,我们将无法帮助您。
  • @saimeunt 添加了完整代码。如果您还需要什么,请告诉我。
  • 所以根据迈克尔梅森的说法,因为你接受了他的回答,最后,这只是一个错字?

标签: javascript mongodb meteor collections database


【解决方案1】:

这是基于链接问题 (Shared Collection Between Client and Server Meteor) 的猜测。在那个问题中,您将集合称为streams Streams = new Meteor.Collection("streams");

但在这个问题中,您使用的是Streams db.Streams.find().forEach(printjson) // Note the capital S in Streams

所以我会说这可能是区分大小写的事情,请尝试: Streams = new Mongo.Collection("Streams"); 这将正确匹配 mongo 集合的名称。还将Meteor.Collection 更改为Mongo.Collection,这是最新的。

【讨论】:

  • 不错,没想到这个。
猜你喜欢
  • 1970-01-01
  • 2013-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-22
  • 2015-04-19
  • 2017-06-02
  • 1970-01-01
相关资源
最近更新 更多