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
3 Answers
Reset to default 3To 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