javascript - How do I extend User model in Meteor? - Stack Overflow

I have been researching this for ages and cannot find a clear explanation. My meteor app has user accou

I have been researching this for ages and cannot find a clear explanation. My meteor app has user accounts installed and logging in/out is all working just fine. However, I'd like to add some optional fields to my users, such as age, gender, etc. How do I go about doing this? Please note, I am new to Meteor so please be explicit.

I have been researching this for ages and cannot find a clear explanation. My meteor app has user accounts installed and logging in/out is all working just fine. However, I'd like to add some optional fields to my users, such as age, gender, etc. How do I go about doing this? Please note, I am new to Meteor so please be explicit.

Share Improve this question edited Nov 5, 2016 at 2:38 Dan Dascalescu 152k65 gold badges333 silver badges420 bronze badges asked Apr 2, 2015 at 21:13 zenben1126zenben1126 6851 gold badge7 silver badges26 bronze badges 1
  • 1 Possible duplicate of MeteorJS: Users collection how to expose new field. – David Weldon Commented Apr 2, 2015 at 21:43
Add a ment  | 

3 Answers 3

Reset to default 3

To add more fields to the user registration form provided by useraccounts packages, see Form Fields Configuration section of the official Guide

Supposing you want to add a gender field to the registration form, you could do something like this

AccountsTemplates.addField({
  _id: "gender",
  type: "select",
  displayName: "Gender",
  select: [
    {
      text: "Male",
      value: "male",
    },
    {
      text: "Female",
      value: "female",
    },
  ],
});

The documentation you're looking for is the Meteor.users collection. It's under "Full API" at http://docs.meteor., which might explain why you've missed it.

A user document can contain any data you want to store about a user. Meteor treats the following fields specially:

  • username: a unique String identifying the user.
  • emails: [...]
  • createdAt: the Date at which the user document was created.
  • profile: an Object which the user can create and update with any data. Do not store anything on profile that you wouldn't want the user to edit unless you have a deny rule on the Meteor.users collection.

[...]

By default, the current user's username, emails and profile are published to the client. You can publish additional fields for the current user with:

// server
Meteor.publish("userData", function () {
  if (this.userId) {
    return Meteor.users.find({_id: this.userId},
                             {fields: {'other': 1, 'things': 1}});
  } else {
    this.ready();
  }
});

// client
Meteor.subscribe("userData");

Check the simple schema package, this package has an example of that

https://atmospherejs./aldeed/simple-schema

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745659985a4638776.html

相关推荐

  • javascript - How do I extend User model in Meteor? - Stack Overflow

    I have been researching this for ages and cannot find a clear explanation. My meteor app has user accou

    21天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信