Skip to main content
Version: v4.6

start section

Using a readingsFilter in a findWithRelatedGraph start section#

You can apply a readingsfilter to a start node in a graph lookup.

In the following example, you can filter a sensor collection for sensors that recorded a temperature greater than 11℃ and in the query response, return the sensors’ parent asset, the asset’s child model elements, and the model element’s child element properties. This query responds with data from each node in the path that matches the query.

Figure: Graph data structure from filtered child start node to parent node, child node, and grandchild node image

The following code example, shows this query:

Example request


{  "$findWithRelatedGraph": {    //start section of the query    "start": {      "collectionDesc": {        "_userItemId": "asset_sensor_1Mc6sZfvBB"      },      "query": {},      //Add a readingsFilter in the start section      "readingsFilter": {        "query": {          "temp": {            "$gte": 11          }        }      }    },    "to": {      "segments": [        {          "relatedDesc": {            //Diverts path direction to parent for this segment only            "_isInverse": true          },          "query": {},          "as": "asset"        },        {          "from": "asset",          "relatedDesc": {            "_relatedUserType":"rvt_elements"          },          "query": {},          "as": "model_element"        },        {          "from": "model_element",          "relatedDesc": {            "_relatedUserType":"rvt_element_props"          },          "query": {},          //Give the node a name to reference in the next hop          "as": "elem_props",          "options": {            "project": {              "properties.Room Name.val":1            }          }        }      ],      "as": "paths",      "response": "path",      "options": {        "page": {          "_offset": 0        }      }    }  }}

Example response


{  "_list": [    {      "_uri": "/nameduseritems/634fcfe8fce2b338d67a6a9c",      "_name": "Temperature Sensors Collection",      "_userType": "iaf_telemetry_timeseries",      "_tipId": "634fcfe8fce2b338d67a6a9d",      "_versions": [        {          "_userItemDbId": "634fcfe8fce2b338d67a6a9c",          "_relatedItems": {            "_pageSize": 1,            "_list": [              {                "paths": {                  "_pageSize": 1,                  "_list": [                    {                      "_userItemId": "asset_coll_XJnkVkss2Y",                      "_userItemVersionId": "634cd7349d34dd31017382df",                      "_id": "634f9911fce2b338d67a6a91",                      "_version": 1,                      "child": {                        "_userItemId": "model_elem_VZWBjehJGa",                        "_userItemVersionId": "634f9944fce2b338d67a6a93",                        "_id": "634f996ffce2b338d67a6a94",                        "_version": 1,                        "child": {                          "_userItemId": "elemprops_6kdc8LsuV4",                          "_userItemVersionId": "634fcb8cfce2b338d67a6a98",                          "_id": "634fcf55fce2b338d67a6a99",                          "_version": 1                        }                      }                    }                  ],                  "_offset": 0,                  "_total": 1                },                "_sourceId": "e3e052f9-0156-11d5-9301-0000863f27ad-00000131",                "_id": "634fd000fce2b338d67a6a9e",                "_metadata": {                  "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                  "_createdAt": 1666174976579,                  "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                  "_updatedAt": 1666174976579                }              }            ],            "_offset": 0,            "_total": 1          },          "_id": "634fcfe8fce2b338d67a6a9d",          "_isTip": true,          "_metadata": {            "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",            "_createdAt": 1666174952855,            "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",            "_updatedAt": 1666174952855          },          "_version": 1        }      ],      "_irn": "itemsvc:nameduseritem:634fcfe8fce2b338d67a6a9c",      "_namespaces": [        "Lnt_GglJp74V"      ],      "_nextVersion": 2,      "_shortName": "asset_sensor",      "_tipVersion": 1,      "_versionsCount": 1,      "_itemClass": "NamedTelemetryCollection",      "_userItemId": "asset_sensor_1Mc6sZfvBB",      "_id": "634fcfe8fce2b338d67a6a9c",      "_description": "Temperature Sensor IoT",      "_metadata": {        "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",        "_createdAt": 1666174952847,        "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",        "_updatedAt": 1666174952847      },      "_kind": "collection"    }  ],  "_referencedItems": {    "elemprops_6kdc8LsuV4": {      "634fcb8cfce2b338d67a6a98": {        "634fcf55fce2b338d67a6a99": {          "_id": "634fcf55fce2b338d67a6a99",          "properties": {            "Room Name": {              "val": "Check Room Number"            }          }        }      }    },    "model_elem_VZWBjehJGa": {      "634f9944fce2b338d67a6a93": {        "634f996ffce2b338d67a6a94": {          "_id": "634f996ffce2b338d67a6a94"        }      }    },    "asset_coll_XJnkVkss2Y": {      "634cd7349d34dd31017382df": {        "634f9911fce2b338d67a6a91": {          "_id": "634f9911fce2b338d67a6a91"        }      }    }  },  "_time": "79ms"}