使用阵列meteor js查询集合

时间:2017-09-30 10:41:17

标签: arrays mongodb meteor publish-subscribe meteor-blaze

我有这种奇怪的情况我不知道究竟是什么问题。在排除故障时,我发现订阅已发布并订阅,因为它已打印在控制台上。当我在Firefox控制台上执行此操作时,它显示此错误SyntaxError: missing : after property id [Learn More]。我不知道语法错误是什么,因为相同的代码适用于其他文件。 如果我从中删除了fetch()函数,则会显示2个正在发布的对象。这意味着发布和sbscription正在运行。我该怎么办? 这是事件功能

students(){
    let myslug = trimInput(Session.get('ReceivedSlug'));
    if (myslug) {
        let mySchoolDoc = SchoolDb.findOne({slug: myslug});
        if (mySchoolDoc) {
            let arrayModuleSchool = StudentSchool.find({schoolId: mySchoolDoc._id});
            if (arrayModuleSchool) {
                var arrayStudentIds = [];
                arrayModuleSchool.forEach(function(studentSchool){
                   arrayStudentIds.push(studentSchool.studentId);
                });
                let subReadiness = SchoolStudents.find({ _id: {$in: arrayStudentIds}}).fetch();
                if (subReadiness) {
                    console.log('before readiness --- ' +arrayStudentIds);
                    console.log('after seting --- ' +subReadiness);
                   return subReadiness;
                } 
            }
        }
    } 
} 

这是发布功能

Meteor.publish('PaginatedStudents', function (skipCount) {
  check(skipCount, Number);
    user = Meteor.users.findOne({_id:this.userId})
    if(user) {
        if(user.emails[0].verified) {
           return SchoolStudents.find({userId: this.userId}, {limit: 2, skip: skipCount});
        } else {
           throw new Meteor.Error('Not authorized');
           return false;
        }
     }
});

追踪器在事情发生变化时重新运行

Session.setDefault('skip', 0);
Tracker.autorun(function () {
    Meteor.subscribe('PaginatedStudents', Session.get('skip'));
});

0 个答案:

没有答案