【问题标题】:how to obtain documents of record in meteor如何在流星中获取记录文件
【发布时间】:2015-09-09 00:48:16
【问题描述】:
Meteor.publish('get',function(){
        return clases.find();
    });

Meteor.subscribe('get');

获取我的出版物的文件

var clases1=clases.find();

_.forEach(clases1, function(claseaux){
claseaux2.name
});

我的集合类有一个名为 name 的属性,但我无法像clasea.name 那样访问它

【问题讨论】:

  • claseaux2 将未定义。去掉“2”。

标签: mongodb meteor collections


【解决方案1】:

Collection.find 返回一个 MiniMongo 游标,而不是一个 JS 数组。

您可以使用Cursor.forEach 来遍历光标,在订阅准备好后将初始文档集发送到客户端:

Meteor.subscribe("get", function(){
  clases.find().forEach(function(claseaux){
    console.log(claseaux.name);
  });
});

【讨论】:

  • 从不进入foreach,但所有文档都在那里
  • 在答案中将Collection.fetch 更改为Collection.find
猜你喜欢
  • 1970-01-01
  • 2012-04-27
  • 1970-01-01
  • 2016-03-19
  • 1970-01-01
  • 1970-01-01
  • 2016-11-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多