【发布时间】:2016-02-13 00:04:29
【问题描述】:
我在服务器端定义了如下发布:
Meteor.publish('observedQuestionsFeed',function(){
_self = this;
return Questions.find({
observedByUsers : {$exists: true,$elemMatch: {$eq:_self.userId}}});
});
返回我需要的;
然后我在我的模板中定义了对该出版物的订阅,如下所示:
Template.observedQuestions.onCreated(function(){
var self = this;
self.autorun(function(){
self.subscribe('observedQuestionsFeed');
});
});
但我无法在我的助手中使用该出版物,因为我需要重复我理解的相同查询,但 $eq 无法识别;
我说:
Template.observedQuestions.helpers({
observedQuestions : function(){
questions = Questions.find({
observedByUsers : {$exists: true,$elemMatch: {$eq:Meteor.userId()}}});
return questions;
}
});
由于 $eq 无法识别而无法正常工作。 我只想在这个特定的模板中使用这个非常具体的出版物。我应该怎么做? (observedByUsers 字段是一个简单的 usersIds 数组,或者在我的 mongo 集合中未定义)
【问题讨论】: