简体   繁体   English

将字段添加到Meteor.users的配置文件部分

[英]Adding fields into the profile section of Meteor.users

I am new to meteor . 我是新来的流星。 I am now trying to add a field in to the profile section of Users collection generated by the accounts.password package. 我现在尝试在一个由account.password包生成的Users集合的个人资料部分中添加一个字段。 I want the field name to be EmplId. 我希望字段名称为EmplId。 Searched in the meteor documentation and found that "The profile is writable by the user by default.If "profile is an Object which the user can create and update with any data" ,can anyone please help me with how the code should be to add a field EmpId in to the Meteor.users collection? Thanks in advance. 在流星文档中搜索,发现“默认情况下该配置文件可由用户写入。如果“配置文件是用户可以用任何数据创建和更新的对象”,请问有人可以帮助我添加代码在Meteor.users集合中输入EmpId字段吗?

While you can add keys to the profile key during Accounts.createUser(), you can also set them later. 您可以在Accounts.createUser()期间将密钥添加到配置文件密钥中,但也可以稍后进行设置。 You simply update the Meteor.users collection as you would any other collection: 您只需像其他集合一样简单地更新Meteor.users集合:

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

Note that when you refer to sub-keys in a collection you need to quote 'key.subkey' - in this case 'profile.emplId' 请注意,当您引用集合中的子项时,需要引用'key.subkey' -在这种情况下为'profile.emplId'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM