How to publish data based on custom profile fields

I have the following code (that doesn’t work, but you get what I’m trying to do):

Meteor.publish('partnerScoreData', function() {
  return UserScores.find({
    userId: this.profile.partnerId
  });
});

I’m trying to publish the document using a value that I have stored on a custom field that I added inside of the user’s profile, right next to firstName and lastName. How can I access this field without being able to the usual “Meteor.user().profile.partnerId” syntax?

Thanks so much!!

Could be an easier/more efficient way, but:

Meteor.publish('partnerScoreData', function () {
  var user = Meteor.users.findOne({
    _id: this.userId
  });
 if (typeof user.profile.partnerId !== 'undefined') {
    return UserScores.find({
      userId: user.profile.partnerId
    });
 }

});

1 Like

Haha that’s exactly what I resorted to. Thanks so much for your response, I really appreciate it!

1 Like