Meteor.userId vs Meteor.userId()

帅比萌擦擦* 提交于 2019-12-21 23:11:44

问题


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?


回答1:


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).




回答2:


I have had the same issue with Meteor.userId() when trying to get a unit testing with mocha to work.

A simple fix is to go to tasks.js and replace Meteor.userId() with this.userId which is to use the this context of the function.



来源:https://stackoverflow.com/questions/24320754/meteor-userid-vs-meteor-userid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!