Groups in Itential Platform can be uniquely identified by a database ID, or by a name and provenance pair where provenance is the name of the AAA adapter from which the group originated. This page covers best practices for group representation and how to query documents with referenced groups.
Reference groups via database ID. In MongoDB, groups are keyed with ObjectId, and references should use that type as well. This allows applications to use $lookup in the MongoDB aggregation pipeline to sort and filter by group fields, and enables more efficient querying when group data needs to be retrieved.
Do not present users with a list of group IDs. Display group lists and references using the group name and provenance fields. Group name alone is no longer sufficient — users may need to distinguish between similarly named groups in different systems.
APIs should accept and return both group IDs and name/provenance pairs depending on context. Where group 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 group document:
Denormalizing group data — for example, storing a copy of the group name alongside the group ID — creates a maintenance problem when the group data changes but the copy does not. Instead, load group data at query time to include it in the API response.
This response includes the group’s human-readable fields alongside the group ID:
This query produces the desired data in a single request to MongoDB: