我看不到我用户的任何个人资料信息,知道为什么吗?
服务器:
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/