The `users` Collection in Meteor
Learn to install the users collection in Meteor and how to determine the user’s login state.
Meteor’s users
collection#
Installing the accounts-password
package creates a collection in the database called users
. This collection is responsible for saving user data. The schema of this collection depends on the accounts
package we’re using. Meteor supports different login providers and accounts packages. Remember that the schema determines the shape of the collection. However, we can also use our own custom schema to validate the creation of a new user.
Here’s an example of the data saved when the accounts-password
package is used. There’s a profile
object in the users
collection that we can add additional fields to. We saw an example in the code that creates a new user in a previous lesson and allowed us to add the address and phone number to the user profile object. We can also add extra data to the users
collection by adding a top-level field instead of adding it to the profile
object. This is done by updating the users
collection like so:
Meteor.users.update(userId, { $set : { fieldToAdd : fieldValue } });
Get hands-on with 1400+ tech skills courses.