How to publish data based on custom profile fields


#1

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!!


#2

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
    });
 }

});


#3

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