最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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

Post a comment

comment list (0)

  1. No comments so far