Unable to publish Current User fields


#1

I have turned off auto publish in my App and am trying to Publish User Data that is submitted after user is creates. Following is my Publishing code on server side …

Meteor.publish("userData", function () {
  if (this.userId) {
    return Meteor.users.find({_id: this.userId},
                             {fields: {'services':1, 'firstLogin':0, 'verified':1, 'skills':1, 'role':1}});
  } else {
    this.ready();
  }
});

And following is my Subscription code.

Meteor.subscribe("userData");

But all I see are _id, firstLogin, services and profile. I can see rest of the fields when i do db.users.find() but I can access them in browser console.

Any help will be much appreciated. Thanks.

Gagan


#2

Do you wait for the subscription to be ready before you try to access the data?


#3

I do have this in my router.js

Router.configure({
  layoutTemplate:  "layout",
  loadingTemplate: "loading",
  notFoundTemplate: "notFound",
  
  waitOn: function() { return Meteor.subscribe('userData'); }
});

#4

Why not just make it automatic using a null publication?

Meteor.publish(null, function () {
  return Meteor.users.find({
    _id: this.userId
  }, {
    fields: {
      services: 1,
      verified: 1,
      skills: 1,
      role: 1
    }
  });
}, { is_auto: true });

Then you can just use Meteor.user() and see this data.


#5

Sorry, I don’t user Iron Router and cannot check if this code works.


#6

You’re a legend mate. Thank You!!
This has been bugging me all day. I can finally get some food :slight_smile:


#7

Hey, I need your help again. I made the user Data publication NULL as you suggested and it was working perfectly. I could turn on and off the fields I wanted to see. But that was all on localhost. I just deployed the App to the Meteor server and once again, all I see are ID, Profile and Services.

Any ideas what could be causing the changes after deploying?