Meteor.userId vs Meteor.userId()

Itinerati picture Itinerati · Jun 20, 2014 · Viewed 11.7k times · Source

I have a short piece of code, like so, to update the name in my user's profile:

Meteor.users.update({_id: Meteor.userId()}, {$set:{"profile.name": name}});

When I'm working locally, I can use Meteor.userId or Meteor.userId() without issue. However, when I deploy to Modulus, I run into issues. If I don't have the operator on it, it will do the initial $set, but no more. If I user the operators, it behaves as I would expect.

Why is this? I assume that I shouldn't have been using this without the operator to begin with, but is there a reason why it worked at all?

Answer

Soren picture Soren · Mar 3, 2015

Have a look in the documentation

  • The function Meteor.userId() is available "Anywhere but publish functions"

  • The variable this.userId is available "Anywhere" (which explicitly is also called out for the Server side Publish function).