7

为了方便起见,我在users集合中定义了一些有用的字段。允许客户访问相应字段的正确方法是什么?我正在使用autopublish包,但从Meteor.user()客户端只显示emails数组。

4

1 回答 1

7

在查询用户集合时,您必须明确告诉 Meteor 要包含哪些用户字段。

例如在客户端发布自定义“头像”字段:

// Client only code
if (Meteor.isClient) {

Meteor.subscribe("currentUserData");
...
} 

// Server-only code
if (Meteor.isServer) {

  Meteor.publish("currentUserData", function() {
    return Meteor.users.find({}, {
      fields : {
        'avatar' : 1
      }
    });
  });   
...
}
于 2013-01-30T11:58:14.380 回答