流星 - 无法访问收藏

Meteor - can't access collection

本文关键字:访问 收藏 流星      更新时间:2023-09-26

我通过shell创建了一个新集合(区域),但由于某种原因,当我尝试发布它时:

Meteor.publish('Areas', function(){
   return Meteor.Areas.find();
});

我收到以下错误:来自子区域 id vSLHezdCrv77i6aca 类型错误的异常:无法调用未定义的方法"查找"。

我对用户表使用完全相同的过程,它工作正常。当我从 mongo shell 查询它时,它也没关系。

任何帮助将不胜感激!

编辑:

订阅代码:

Template.content_profile.onCreated(function() {
    var self = this;
    self.autorun(function() {
      var id = FlowRouter.getParam('id');
       self.subscribe('profileInfo', id);
       self.subscribe('Areas');
    });
    console.log(Areas.find().count());
  });"

您不必在它前面加上 Meteor:

Areas = new Mongo.Collection("areas");
Meteor.publish('Areas', function(){
   return Areas.find();
});