relatedFilter and related
relatedFilter and related section query combination in a $findWithRelated query#
You can query the child items of parent items you filter by using both a relatedFilter and a related query.
Add your relatedFilter and related query in a $findWithRelated query as follows:
- To filter parent items, add a
relatedFilter. For more information, see relatedFilter in findWithRelated query fields table. - To query the child items of the parent items you filtered with the
relatedFilter, add a simple query in therelatedsection of thefindWithRelatedquery. For more information, see findWithRelated query fields table.
For real world examples, see the following example query and response:
Example query
{ "$findWithRelated": { "parent": { "collectionDesc": { "_userItemId": "asset_coll_zGPDR22aoS", "_userType": "iaf_ext_asset_coll" }, "collectionProject": { "_userItemId": 1, "_name": 1 }, "query": { "properties.dtType.val": "Single Glass Door" }, "options": { "project": { "Asset Name": 1, "properties.Description": 1, "properties.dtType": 1, "properties.BA Asset": 1 }, "page": { "_pageSize": 100, "_offset": 0 }, "sort": { "_metadata._updatedAt": 1 } } }, "relatedFilter": { "includeResult": true, "$and": [ { "relatedDesc": { "_relatedUserType": "rvt_elements" }, "query": { "source_id": "3930258d-f214-461b-a69b-cafb3344fa16-00048122" }, "options": { "project": { "_metadata": 0 }, "page": { "_pageSize": 100, "_offset": 0 }, "sort": { "_metadata._updatedAt": 1 } }, "as": "elements" } ] }, "related": [ { "relatedDesc": { "_relatedUserType": "iaf_dt_spec_data_coll" }, "query": {}, "options": { "project": { "properties.Structural Opening (H X W Mm)": 1, "properties.Fire Rating (Mins) As Per Schedule": 1, "properties.Frame Size (H X W Mm)": 1 }, "page": { "_pageSize": 100, "_offset": 0 } }, "as": "spec_data" } ] }}Example response
{ "_list": [ { "_uri": "/nameduseritems/5fa25c96b699d03bfcc81247", "_name": "Asset Collection", "_tipVersion": 1, "_itemClass": "NamedUserCollection", "_userItemId": "asset_coll_zGPDR22aoS", "_tipId": "5fa25c96b699d03bfcc81248", "_versions": [ { "_userItemDbId": "5fa25c96b699d03bfcc81247", "_relatedItems": { "_pageSize": 11, "_list": [ { "Asset Name": "Single Glass Door 143 D-G-046 Tenant CAFE/RETAIL - 81", "elements": { "_pageSize": 1, "_list": [ { "sourceId": "3930258d-f214-461b-a69b-cafb3344fa16-00048122", "relationships": { "hosted_by": [ 1563 ], "contained_by_spatial_structure": 90974 }, "dtCategory": "Door - External", "dtType": "Single Glass Door", "type_id": 92975, "_id": "5fa259b2c4c347b3ea9d43cc", "id": 1564, "package_id": 1564, "source_id": "3930258d-f214-461b-a69b-cafb3344fa16-00048122", "type": 92975 } ], "_offset": 0, "_total": 1 }, "_id": "5fa25cbbb699d03bfcc8124c", "properties": { "Description": { "val": "Door", "dName": "Description", "type": "text" }, "dtType": { "val": "Single Glass Door", "dName": "dtType", "type": "<<HIERARCHY>>" }, "BA Asset": { "val": "Doors", "dName": "BA Asset", "type": "text" } }, "spec_data": { "_pageSize": 1, "_list": [ { "_id": "5fa261f443e5136e76b62a0a", "properties": { "Structural Opening (H X W Mm)": { "dName": "Structural Opening (H X W Mm)", "epoch": null, "type": "text" }, "Fire Rating (Mins) As Per Schedule": { "dName": "Fire Rating (Mins) As Per Schedule", "epoch": null, "type": "text" }, "Frame Size (H X W Mm)": { "dName": "Frame Size (H X W Mm)", "epoch": null, "type": "text" } } } ], "_offset": 0, "_total": 1 } } ], "_offset": 0, "_total": 11, "_filteredSize": 1 }, "_id": "5fa25c96b699d03bfcc81248", "_isTip": true, "_metadata": { "_updatedById": "bee7e3ce-9d85-48ee-aff3-4cbcd34d6bdc", "_createdAt": 1604476054215, "_createdById": "bee7e3ce-9d85-48ee-aff3-4cbcd34d6bdc", "_updatedAt": 1604476054215 }, "_version": 1 } ], "_irn": "itemsvc:nameduseritem:5fa25c96b699d03bfcc81247", "_id": "5fa25c96b699d03bfcc81247", "_kind": "collection" } ], "_time": "62ms"}