Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在访问Meteor.users.emails[0]。Meteor.publish中的地址_Meteor - Fatal编程技术网

正在访问Meteor.users.emails[0]。Meteor.publish中的地址

正在访问Meteor.users.emails[0]。Meteor.publish中的地址,meteor,Meteor,我想将集合发布给this.userId访问的所有者(该部分正在工作)以及所有者邀请的所有者。我能做到这一点的唯一方法是通过我收藏中的invested.email,因为被邀请的用户可能还不是注册用户 Meteor.publish("meals", function () { var current_user = Meteor.user(); return MealModel.find( {$or: [{"invited.email": current_user.emails[0].

我想将集合发布给this.userId访问的所有者(该部分正在工作)以及所有者邀请的所有者。我能做到这一点的唯一方法是通过我收藏中的invested.email,因为被邀请的用户可能还不是注册用户

Meteor.publish("meals", function () {
  var current_user = Meteor.user();
    return MealModel.find(
  {$or: [{"invited.email": current_user.emails[0].address}, {owner: this.userId}]});
});
我不想在客户端发布整个集合和查询,因为我担心集合可能会变得太大


有什么建议吗?谢谢。

不幸的是,您不能在发布函数内部使用。相反,您需要使用
userId
执行
findOne
。尝试一下:

Meteor.publish('feeds',function(){ 如果(!this.userId) 返回这个.ready(); var user=Meteor.users.findOne(this.userId); var email=user.emails[0]。地址; 返回MealModel.find({$or:[{'invested.email':email},{owner:this.userId}]}); });
请原谅,返回部分不应该是{owner:user}而不是{owner:this.userId}?(我的美托尔体验目前非常有限,所以请恕我直言)@EvilBeer我想你可能是对的,因为用户已经打过电话了,所以再打一次也没有意义,对吧?@David Weldon,就是这样,谢谢。我会投票支持你,但我的名声不好。@user
user
是一个对象,
this.userId
user.\u id
(这些是相同的)是字符串。我的假设是,
MealModel
文档插入时将
owner
作为id(正常)而不是对象(异常)。@DavidWeldon ah,这是有道理的。道歉