relatedDistinctFields
relatedDistinctFields filter in a $findWithRelated query
Insert a relatedDistinctFields filter in your $findWithRelated query to get the field values of child items.
For more information on the relatedDistinctFields filter fields and how you insert the filter in a findWithRelated query request, see the following example code structure with reference to Table 1:
Note: For more information on the $findWithRelated query, see findWithRelated query.
relatedDistinctFields filter in a findWithRelated query
"$findWithRelated": {
"parent": {
//parent object that contains the look up criteria for the parent collection and related items
},
"relatedDistinctFields": [
{
"relatedDesc": {
"<criteria to look up parent-child relationship>": "<value>"
},
"field": "<property you want to query>",
"query": {
"<the value you put in the field property above>": {
//simple query such as the following example
"$in": ["Steel", "Wood"]
}
}
}
]
}
Table 1: relatedDistinctFields filter in a $findWithRelated query fields table
| Field | Type | Required | Description |
|---|---|---|---|
parent | Object | Required | You must add a parent object that contains the look up criteria for the parent collection and related items. For more information, see parent and its nested object properties in findWithRelated query fields table. |
relatedDistinctFields | List | Optional | Use to filter the parent related items based on your query of the field values of their child related items. Add a list of relatedDistinctField query objects, which can contain relatedDesc, field, and query properties. Note: You can use relatedDistinctFields with relatedFilter but not with a related query. |
relatedDistinctFields.relatedDesc | Object | Required | Add your relationship query for parent related items as a valid simple query. For more information on query operators, see Supported query operators. |
relatedDistinctFields.field | String | Required | Enter the name of the field that contains the values you want to look up. To access subdocument fields or arrays, use dot notation, for example, properties.name. |
relatedDistinctFields.query | Object | Optional | Add a relationship query to filter the child related items you queried in the relatedDistinctFields.field lookup. You must enter a valid simple query. |
For real world examples, see the following example query and response:
Example query
{
"$findWithRelated": {
"parent": {
"collectionDesc": {
"_userItemId": "3_ba_elem_Ik9zmx6o7O"
},
"collectionProject": {
"_userItemId": 1,
"_name": 1
},
"query": {
"assetType": "Doors"
},
"options": {
"project": {
"_metadata": 0
}
}
},
"relatedDistinctFields": [
{
"relatedDesc": {
"_relatedUserType": "rvt_element_props"
},
"field": "properties.Manufacturer.val",
"query": {
"properties.Material.val": {
"$in": ["Steel", "Wood"]
}
}
},
{
"relatedDesc": {
"_relatedUserType": "rvt_element_props"
},
"field": "properties.Material.val",
"query": {
"properties.Manufacturer.val": {
"$in": ["ABC Company", "GHI Company"]
}
}
}
]
}
}
Example response
{
"_list": [
{
"_uri": "/nameduseritems/5e1c4672fdf26e660c5f5a4c",
"_name": "3_elements",
"_tipVersion": 2,
"_itemClass": "NamedUserCollection",
"_userItemId": "3_ba_elem_Ik9zmx6o7O",
"_tipId": "5e1c4ac9fdf26e660c5f5b15",
"_versions": [
{
"_relatedDistinctFields": [
{
"properties.Manufacturer.val": [
"ABC Company",
"GHI Company"
]
},
{
"properties.Material.val": [
"Wood",
"Steel"
]
}
],
"_userItemDbId": "5e1c4672fdf26e660c5f5a4c",
"_id": "5e1c4672fdf26e660c5f5a4d",
"_isTip": false,
"_metadata": {
"_updatedById": "bf03bc5f-bfe4-40f4-91fd-5ece6effbe99",
"_createdAt": 1578911346385,
"_createdById": "bf03bc5f-bfe4-40f4-91fd-5ece6effbe99",
"_updatedAt": 1578912457236
},
"_version": 1
}
],
"_irn": "itemsvc:nameduseritem:5e1c4672fdf26e660c5f5a4c",
"_id": "5e1c4672fdf26e660c5f5a4c",
"_kind": "collection"
}
],
"_time": "26ms"
}