Publish certain information for Meteor.users and more information for Meteor.user

前端 未结 3 2002
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 08:21

I want to have client-side access for a certain set of fields for ALL users while I would like to have access to even more fields for the current user only. How do I go abou

3条回答
  •  自闭症患者
    2020-11-28 08:32

    As mentioned above, the

    Meteor.publish("userData", function () {
        return Meteor.users.find({_id: this.userId},
            {fields: {'other': 1, 'things': 1}});
    });
    

    and

    Meteor.publish("allUserData", function () {
      return Meteor.users.find({}, {fields: {'nested.things': 1}});
    });
    

    publish functions will push the data from the Users collection.

    Subscribe with

    Tracker.autorun(function () {
        Meteor.subscribe("userData");
        Meteor.subscribe("allUserData");
    });
    

    And the additional data will automatically go into the Users collection and be available in the Meteor.user() object.

提交回复
热议问题