查询Meteor集合(在本地主机上工作,在服务器上失败)

Querying Meteor collection (works on the localhost, fails on server)

本文关键字:工作 服务器 失败 集合 Meteor 查询 主机      更新时间:2023-09-26

我刚刚开始Meteor的小项目,有几个月的经验。我建立了一个名为Reactions的集合,并将csv数据导入MongoDB。

现在,当我从localhost(win7)查询它时,我得到了预期的记录集,但一旦我从远程服务器查询它,我就得到了emty集。

由于这似乎是一个订阅时间问题,因为收集的记录约为1万条,我在Iron Router路由中添加了"waitOn"子句,但无济于事。

我到处寻找类似的问题,大多数建议等待,所以我已经没有主意了。

请参阅下面的相关代码,并提前感谢您的任何提示

----------/bboth/collections/Requestion.js----------------反应=新的Mongo.Collection("反应",{idGeneration:"Mongo"});----------/server/publications.js----------------Meteor.publish("操作",function(){return Reactions.find();});----------/client/views/subscriptions.js----------------Meteor.subscribe("操作",function(){return Reactions.find();});----------/bboth/lib/router.js----------------this.route("行动"{其中:"服务器",waitOn:function(){return Meteor.subscribe('操作');},操作:函数(){var action=this.request.body.action;var reactions=reactions.find({action:action}).fetch();console.log('reactions.length='+reactions.length);

您的路由操作需要涉及渲染。您的find()可以在data:函数中运行。为什么where:会起作用?订阅需要在客户端上运行!

this.route('reactions', {
  waitOn: function() { 
    return Meteor.subscribe('reactions');
  },
  action: function () {
    this.render('myLayout'); 
  }, 
  data: function(){
    var action = this.request.body.action;
    return Reactions.find( { action: action } ); // you don't need to .fetch(), just return a cursor
  }
});