Docs Menu
Docs Home
/ /
Atlas Device SDKs
/

Custom User Data

On this page

  • Prerequisites
  • Create Custom User Data
  • Read Custom User Data
  • Update Custom User Data
  • Delete Custom User Data

This page describes custom user data in an App Services App and how to manage it with Atlas Device SDK.

Atlas App Services lets you associate data with an authenticated user, such as a user's preferred language, date of birth, or local timezone. You can store this arbitrary custom user data about your users and read it from your client application.

To use custom user data, you must have an App Services App with custom user data enabled.

To set up an App Services App that uses custom user data, refer to the following:

  1. Enable Custom User Data in the App Services documentation

  2. Connect to Atlas

When you configure custom user data in Atlas, you designate a database and collection to store the custom user data. This data is stored as documents in Atlas.

To create custom user data for a user, create a MongoDB document in the custom user data collection. The user ID field of the document should contain the user's user ID. You can create custom user data documents in a few ways:

  • Define a User Creation Function that automatically creates custom user data as part of the user registration process.

  • Define a Function that you call with the user data, perhaps sometime after registration.

  • Access MongoDB through the SDK, if your language supports it, and insert a document directly into the custom user data collection.

  • Manually create a custom data document through:

Tip

In the App Services UI, check the App Users page under the Custom User Data tab to find and configure custom user data settings, including:

  • The custom user data cluster, database, and collection

  • The user ID field used to map custom user data documents to users

You can add any number of arbitrary fields and values to the custom user data document when you create it. The user ID field is the only requirement for the document to become available on the User object as custom user data.

You can read the custom user data of a currently logged-in user through that user's User object. You cannot edit custom user data through a User object. To edit custom user data, see the Update Custom User Data section on this page.

Warning

Custom Data May Be Stale

Atlas App Services does not dynamically update the value of the client-side user custom data document immediately when underlying data changes. Instead, App Services fetches the most recent version of custom user data whenever a user refreshes their access token, which is used by most SDK operations that contact the App Services backend. If the token is not refreshed before its default 30 minute expiration time, the SDK refreshes the token on the next call to the backend. Custom user data could be stale for up to 30 minutes plus the time until the next SDK call to the backend occurs.

You can update custom user data in a few ways:

  • Define a Function that you call with the updated user data.

  • Access MongoDB through the SDK, if your language supports it, and update the user data document in the custom user data collection directly.

  • Manually update a custom data document through:

Custom user data is stored in a document linked to the user object. Deleting a user does not delete the custom user data. To fully delete user data to comply with, for example, Apple's Account deletion guidance, you must manually delete the user's custom data document.

You can delete custom user data in a few ways:

  • Define a Function that you call to delete custom user data.

  • Access MongoDB through the SDK, if your language supports it, and delete the user data document from the custom user data collection directly.

  • Manually delete a custom data document through:

← Manage User Tokens