Meteor 用户配置文件始终未定义

标签 meteor

我看不到我用户的任何个人资料信息,知道为什么吗?

服务器:

Meteor.publish("userData", function () {
    return Meteor.users.find({_id: this.userId},
        {fields: {'profile': 1}});
});
Meteor.publish("allUsers", function () {
    //TODO: For testing only, remove this
    return Meteor.users.find({}, {fields: {'profile': 1}});
});

客户:

Meteor.autosubscribe(function () {
    Meteor.subscribe('allUsers',null , function() { console.log(Meteor.users.find().fetch()) });
    Meteor.subscribe('userData', null, function() { console.log(Meteor.user())});
});

....

Accounts.createUser({email:email,password:password, profile: {name: name}},function(error){
    ...
});

我的控制台输出一个对象,第一个对象只有 _id 和电子邮件,第二个对象是未定义的。 配置文件信息(在我的例子中是名称)似乎有效,因为在我的 server.js 中我有一个工作正常的名称验证:

Accounts.onCreateUser(function(options, user) {
    if(options.profile.name.length<2)
        throw new Meteor.Error(403, "Please provide a name.");
    return user;
});

我错过了什么吗?

谢谢!

最佳答案

使用多个订阅时,只有 first subscription matters .第二个订阅(如果包含相同的集合)将被忽略,因为它与第一个订阅冲突。

不过,您也可以这样做:

服务器:

var debugmode = false; //set to true to enable debug/testing mode
Meteor.publish("userData", function () {
    if(debugmode) {
        return Meteor.users.find({}, fields: {'profile': 1}});
    }
    else
    {
        return Meteor.users.find({_id: this.userId},{fields: {'profile': 1}});
    }
});

客户:

Meteor.autosubscribe(function () {
    Meteor.subscribe('userData', null, function() { console.log(Meteor.user()); console.log(Meteor.users.find({}).fetch());});
});

关于Meteor 用户配置文件始终未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14557212/

相关文章:

javascript - Spotify json 响应包含换行符?

Meteor.js 0.6.5 和 Cloud 9

css - 如何测试 LESS 文件是否正在编译?

node.js - 热推网站代码ala Meteor

javascript - 我无法在类(class)之间切换

meteor - windows 下的meteor命令行中的环境变量

javascript - 应用程序部署到 Meteor.com 后就会停止工作?

javascript在 meteor 中生成重复的图像

javascript - 在 Meteor 中使用动态变量访问另一个变量的值?

Meteor 用户帐户问题 - 使用 OAuth 服务创建重复帐户 (accounts-google)