【发布时间】:2017-05-13 12:19:43
【问题描述】:
此 Meteor 服务器代码给出以下错误:
Meteor.publish('myCol', function (age) {
if (!this.userId) return;
if (Meteor.user().profile.hasOwnProperty('gotNoAge')) return; //<=== error line
console.log('publishing for age: ' + age);
return MyCol.find({age: age}, {
fields: {
myField: true
}, limit: 1
});
});
错误:Meteor.userId 只能在方法调用中调用。在发布函数中使用 this.userId。
我尝试将“错误行”更改为以下内容,但无济于事。
if (Meteor.users.find({_id:this.userId}).profile.hasOwnProperty('gotNoAge')) return;
有什么建议吗?谢谢
【问题讨论】:
-
试试
findOne
标签: meteor