Meteor - Why should I use this.userId over Meteor.userId() whenever possible?

后端 未结 2 1140
醉话见心
醉话见心 2021-01-19 15:48

Judging from this comment by David Glasser in the GitHub issues:

this.userId is the primary API and Meteor.userId() is synta

2条回答
  •  一个人的身影
    2021-01-19 16:12

    Simply speaking, Meteor.userId() queries the DB everytime you use it. In client side ( logically ), it looks fine - since we have minimongo.

    In server side, using Meteor.userId(), consumes extra resources on SERVER, which, at times is undesired.

    Now, this.userId is more over like a session variable m ie it will have a value only when there is a userid attached with the current session. And hence,using 'this' reference wont go and fetch the database everytime, but rather than that it used the active session userId.

    Consider performance as a factor. That is the main reason for using this.userId rather than Meteor.userId

提交回复
热议问题