segment
Using a readingsFilter in a findWithRelatedGraph segment#
You can apply a readingsfilter to a segment to filter nodes in the path.
In the following example, you can start from an asset’s model element collection and get any parent assets whose sensors recorded temperatures greater than 10℃. In this case, the filter is on the final node in the path, which is the sensors collection. This query responds with data from each node in the path that matches the query.
Figure: Graph data structure from start child node to parent node, to filtered child node
The following code example, shows this query:
Example request
{ "$findWithRelatedGraph": { "start": { "collectionDesc": { "_userItemId": "model_elem_VZWBjehJGa" } }, "to": { "segments": [ { "relatedDesc": { //Diverts path direction to parent for this segment only "_isInverse": true }, "query": {}, "options": { "project": { "Asset Name": 1, "properties.dtCategory.val":1 } }, "as": "asset" }, { "from": "asset", "relatedDesc": { "_relatedUserItemId": "asset_sensor_1Mc6sZfvBB" }, "query": {}, "options": { "project": { "_sourceId": 1 } }, //Add a readingsFilter in the segments section for the segment you want to filter "readingsFilter": { "query": { "temp": { "$gt": 10 } } }, "as": "sensor" } ], "as": "paths" } }}
Example response
{ "_list": [ { "_uri": "/nameduseritems/634f9944fce2b338d67a6a92", "_name": "Building assets Collection", "_userType": "rvt_elements", "_tipId": "634f9944fce2b338d67a6a93", "_versions": [ { "_userItemDbId": "634f9944fce2b338d67a6a92", "_relatedItems": { "_pageSize": 1, "_list": [ { "dtCategory": "HVAC Air Handling Unit", "paths": { "_pageSize": 1, "_list": [ { "_userItemId": "asset_coll_XJnkVkss2Y", "_userItemVersionId": "634cd7349d34dd31017382df", "_id": "634f9911fce2b338d67a6a91", "_version": 1, "child": { "_userItemId": "asset_sensor_1Mc6sZfvBB", "_userItemVersionId": "634fcfe8fce2b338d67a6a9d", "_id": "634fd000fce2b338d67a6a9e", "_version": 1 } } ], "_offset": 0, "_total": 1 }, "_id": "634f996ffce2b338d67a6a94", "_metadata": { "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec", "_createdAt": 1666161007152, "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec", "_updatedAt": 1666161007152 } } ], "_offset": 0, "_total": 1 }, "_id": "634f9944fce2b338d67a6a93", "_isTip": true, "_metadata": { "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec", "_createdAt": 1666160964708, "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec", "_updatedAt": 1666160964708 }, "_version": 1 } ], "_irn": "itemsvc:nameduseritem:634f9944fce2b338d67a6a92", "_namespaces": [ "Lnt_GglJp74V" ], "_nextVersion": 2, "_shortName": "model_elem", "_tipVersion": 1, "_versionsCount": 1, "_itemClass": "NamedUserCollection", "_userItemId": "model_elem_VZWBjehJGa", "_id": "634f9944fce2b338d67a6a92", "_metadata": { "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec", "_createdAt": 1666160964700, "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec", "_updatedAt": 1666160964700 }, "_kind": "collection" } ], "_referencedItems": { "asset_sensor_1Mc6sZfvBB": { "634fcfe8fce2b338d67a6a9d": { "634fd000fce2b338d67a6a9e": { "_sourceId": "e3e052f9-0156-11d5-9301-0000863f27ad-00000131", "_id": "634fd000fce2b338d67a6a9e" } } }, "asset_coll_XJnkVkss2Y": { "634cd7349d34dd31017382df": { "634f9911fce2b338d67a6a91": { "Asset Name": "5SPD.R1.HV.AHU.0004", "_id": "634f9911fce2b338d67a6a91", "properties": { "dtCategory": { "val": "HVAC Air Handling Unit" } } } } } }, "_time": "91ms"}