由于$ eq,meteor客户端查找无效

时间:2016-02-13 11:45:32

标签: mongodb meteor

我订阅了我的服务器出版物如下:

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;

    }
});

但由于$ eq无法在minimongo中识别,因此无效。 怎么解决?

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" ] 
}

1 个答案:

答案 0 :(得分:0)

根据您的示例Questions文档判断,字段observedByUsers是一个包含用户ID的简单数组。

因此,您只需使用以下查询:

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