Reference user accounts
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.
Best practices
Account references in database documents
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.
Accounts in the UI
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.
Account references in APIs
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.
Query, filter, and sort account documents
Example account document
The examples below use the following account document:
Query documents with referenced accounts
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.
Example workflow document
Example API response with inline account data
This response includes the human-readable username and provenance fields alongside the account ID:
Aggregation pipeline query
This query produces the desired data set in a single request to MongoDB:
Filter and sort documents by referenced account fields
You can extend the pipeline above to filter and sort by account fields: