2016-02-13 92 views
1

我订阅了我的服务器的发布如下:

Template.observedQuestions.onCreated(function(){ 
    var self = this; 
    self.autorun(function(){ 
     self.subscribe('observedQuestionsFeed'); 
    }); 
}); 

现在我需要使用辅助函数来获取我的数据:

Template.observedQuestions.helpers({ 
    observedQuestionsList : function(){ 
     questions = Questions.find({ 
        observedByUsers : {$exists: true,$elemMatch:{$eq:Meteor.userId()}}}); 
     return questions; 

    } 
}); 

,但它确实由于未能在minimongo中识别$ eq而无法工作。 如何解决它?

DOC样品:

{ 
    "_id" : "rP4JP8jkprwwi3ZCp", 
    "qUserId" : "NLLW3RBXqnbSGuZ3n", 
    "type" : "question", 
    "date" : ISODate("2016-02-13T11:23:10.845Z"), 
    "subject" : "test", 
    "question" : "test", 
    "replies" : [ 
     { 
      "rID" : "LphcqKnkTHf25SCwq", 
      "rUserID" : "NLLW3RBXqnbSGuZ3n", 
      "date" : ISODate("2016-02-13T11:23:10.847Z"), 
      "answer" : "reply1." 
     }, 
     { 
      "rID" : "HxaohnEgxwNJLtf2z", 
      "rUserID" : "NLLW3RBXqnbSGuZ22", 
      "date" : ISODate("2016-02-13T11:23:10.848Z"), 
      "answer" : "reply2" 
     } 
    ], 
    "observedByUsers" : [ "Bi24LGozvtihxFrNe" ] 
} 
+0

能否请您提供您的'Questions'采集的样本文件? –

+0

我添加了示例文档 – marcinwal

+1

为什么不使用'Questions.find({observedByUsers:Meteor.userId()});'? –

回答

0

从样品Questions文档来看,字段observedByUsers是一个简单的数组,它包含用户ID。

其结果是,你可以简单地使用下面的查询:

Questions.find({observedByUsers: Meteor.userId()}); 
+0

谢谢;我像往常一样过于复杂。 – marcinwal

+0

@marcinwal欢迎您!祝你今天愉快。 –