【问题标题】:Meteor publish unique user always return nothing or undefinedMeteor 发布唯一用户始终不返回任何内容或未定义
【发布时间】:2019-01-11 06:17:16
【问题描述】:

我想知道为什么Meteor.users.find(this.userId); 总是什么都不返回。当我在控制台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

【问题讨论】:

    标签: meteor publish-subscribe userid


    【解决方案1】:

    find 不返回文档(它返回一个游标)。请改用findOne

    var users = Meteor.users.findOne( this.userId );
    

    【讨论】:

    • 虽然之前已经在 Meteor 论坛上解决了。谢谢。
    猜你喜欢
    • 2021-03-14
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多