流星发布唯一用户总是 return 没有或未定义
Meteor publish unique user always return nothing or undefined
我想知道为什么 Meteor.users.find(this.userId);
总是 return 什么都没有。当我在控制台 this.userId
上回显时,它会打印出来。
代码:
Meteor.publish('login.user', function () {
if (this.userId) {
console.log( "current logged in user ---" +this.userId );
var users = Meteor.users.find( this.userId );
if ( users && users._id ) {
console.log( "meteor.users.find() call -- " +users && users._id );
return users && users._id;
}
}
});
控制台日志
I20180803-11:59:20.085(1)? current logged in user ---7EQGhuBszukhsYQa3
find
没有 return 文档(它 return 是一个游标)。使用 findOne
代替:
var users = Meteor.users.findOne( this.userId );
我想知道为什么 Meteor.users.find(this.userId);
总是 return 什么都没有。当我在控制台 this.userId
上回显时,它会打印出来。
代码:
Meteor.publish('login.user', function () {
if (this.userId) {
console.log( "current logged in user ---" +this.userId );
var users = Meteor.users.find( this.userId );
if ( users && users._id ) {
console.log( "meteor.users.find() call -- " +users && users._id );
return users && users._id;
}
}
});
控制台日志
I20180803-11:59:20.085(1)? current logged in user ---7EQGhuBszukhsYQa3
find
没有 return 文档(它 return 是一个游标)。使用 findOne
代替:
var users = Meteor.users.findOne( this.userId );