User accounts are uniquely identified in Itential Platform by a database ID, or by a username and provenance pair where provenance is the name of the AAA adapter from which the account originated. This page covers best practices for user account representation, including how to reference accounts in documents, return account data from APIs, and query and sort documents with referenced accounts.
Reference user accounts via database ID. In MongoDB, accounts are keyed with ObjectId, and references should use that type as well. This allows the application to use $lookup in the MongoDB aggregation pipeline for sorting, filtering, and efficient querying when account data needs to be retrieved.
Do not present users with a list of account IDs. Display user lists and references using the username and provenance fields. Username alone is no longer sufficient — users may need to distinguish between similarly named accounts in different systems.
Based on how existing APIs and documents are structured, APIs should accept and return both account IDs and username/provenance pairs. Where account IDs are exposed, they should appear as strings in JSON. APIs must take on the burden of validating IDs, converting them to ObjectId where appropriate, and testing for equality using the appropriate methods.
The examples below use the following account document:
Denormalizing user account data — for example, storing a copy of the username alongside the account ID — creates a maintenance problem when the account data changes but the copy does not. Instead, load account data at query time to include it in the API response.
This response includes the human-readable username and provenance fields alongside the account ID:
This query produces the desired data set in a single request to MongoDB:
You can extend the pipeline above to filter and sort by account fields: