最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论