User Objects¶
Overview¶
MongoDB Realm represents each application user internally with a User Object that includes a unique ID and additional metadata that describes the user. You can access user objects in the following ways:
- In a Function by accessing context.user.
- In rule expressions with the
%%user
expansion. - In Android, iOS, Node, and React Native client applications.
Schema¶
User objects have the following form:
{ "id": "<Unique User ID>", "type": "<User Type>", "data": { "<Metadata Field>": <Value>, ... }, "custom_data": { "<Custom Data Field>": <Value>, ... }, "identities": [ { "id": <Unique Identity ID>, "provider_type": "<Authentication Provider>", "data": { "<Metadata Field>": <Value>, ... } } ] }
Field | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | string | A string representation of the ObjectId that uniquely identifies the
user. | ||||||||||||||||
type | string | The type of the user. The following types are possible:
| ||||||||||||||||
data | document | A document that contains metadata that describes the
user. This field combines the data for all Note System Functions Have No User Data In system functions, the | ||||||||||||||||
custom_data | document | A document from your application's custom user
data collection that
specifies the user's ID. You can use the custom user data
collection to store arbitrary data about your application's
users. If you set the Note Avoid Storing Large Custom User Data Custom user data is limited to | ||||||||||||||||
identities | array | A list of authentication provider identities associated with the user. When a user first logs in with a specific provider, Realm associates the user with an identity object that contains a unique identifier and additional metadata about the user from the provider. For subsequent logins, Realm refreshes the existing identity data but does not create a new identity. Identity objects have the following form:
|
In general, MongoDB Realm creates a user object for a given user the first time that they authenticate. If you create a test Email/Password user through the Realm UI, Realm creates that user's user object immediately.
Summary¶
- The user object contains relevant information about the user that you can use in your app logic.
- The exact information contained in the user object depends on the authentication providers used.