如何向当前登录用户添加新字段 (Meteor.user())?

How to add new field to current logged in user (Meteor.user())?

我正在尝试使用 PeerJS 库来实现音频通话。我希望用户能够根据他的 peerId 呼叫特定用户。我能想出的唯一方法是将当前登录的 peerId 存储在数据库中他的文档中。

我的问题是,如何向 Meteor.user() 文档添加新字段?

用户数据库可通过 Meteor.users 访问,如 docs. Further reading in the guide 中所述,说明任何字段都可以添加到用户文档中,因此您可以在根文档级别设置自己的对象存储对等连接信息。设置 accounts 包以便登录用户可以从客户端更新用户文档的 profile 字段,除非已设置 deny 访问规则。所以,你可以做你想做的事情,比如:

Meteor.users.update(Meteor.userId(), { $set: { 'profile.peerId': desiredPeerId } })