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

Meteor用户配置文件始终未定义,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 retur

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

服务器:

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和电子邮件,第二个对象没有定义。 配置文件信息(在我的例子中是名称)似乎有效,因为在my server.js中,我有一个名称验证,可以正常工作:

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

if(options.profile.name.length当使用多个订阅时,仅忽略包含相同集合的第二个订阅,因为它与第一个订阅冲突

不过,您可以这样做:

服务器:

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());});
});
发现问题:

在onCreateUser函数中,我需要将此配置文件信息从选项添加到用户对象,因此我的函数应该如下所示:

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

如果(options.profile.name.length这是我正在使用的解决方法,放在~/server/createAccount.js中,我遇到的问题是,如果配置文件未定义,我会出错。这似乎可以通过在创建帐户时创建配置文件来解决问题

希望这是有用的。在github问题评论中找到它,在下面的评论中:

// BUGFIX via https://github.com/meteor/meteor/issues/1369 @thedavidmeister
// Adds profile on account creation to prevent errors from profile undefined on the profile page
Accounts.onCreateUser(function(options, user) {
  user.profile = options.profile ? options.profile : {};
  return user;
});

很高兴知道,谢谢你的回答!但这仍然不能解决我的问题,因为日志对象中没有返回用户配置文件数据,只有_id和电子邮件