Skip to main content
Version: v4.5

Related section

Using a readingsFilter in the related section of a $findWithRelated query#

Insert a readingsFilter in the related section of a $findWithRelated query to return the related items, such as HVAC air handling units, in a collection that have a relationship to telemetry items whose readings match your query.

Structure your $findWithRelated query as follows:


{  "$findWithRelated": {    "parent": {      "collectionDesc": {        "<property to identify a collection you want to query. In this example, an asset collection>": "<identifying value>"      },      "query": {        //<simple query to find matching related items in the collection.         //In this example we want to find HVAC air handling units>                  },    },    "related": [      {        "relatedDesc": {          "<property to identify the telemetry collection you want>": "<value>"        },        "readingsFilter": {          "query": {            //<Valid simple telemetry reading query to filter parent             //related items, in this example, HVAC air handling units>           },        }        "as": "sensor",      }    ]  }}

The following code example returns a list of HVAC units whose sensors recorded a temperature above 11℃ on or after 09:00, December 1st, 2021:

Example request


{  "$findWithRelated": {    "parent": {      "query": {        "properties.dtCategory.val": "HVAC Air Handling Unit"      },      "collectionDesc": {        "_userItemId": "asset_coll_jPQCU4n096"      }    },    "related": [      {        "relatedDesc": {          "_relatedUserType": "iaf_telemetry_timeseries"        },        "readingsFilter": {          "query": {            "$and": [              {                "temp": {                  "$gte": 10                }              }            ]          }        },        "as": "sensor"      }    ]  }}

Example response


{  "_list": [    {      "_uri": "/nameduseritems/634cd7e89d34dd31017382e0",      "_name": "Building assets Collection",      "_userType": "iaf_ext_asset_coll",      "_tipId": "634cd7e89d34dd31017382e1",      "_versions": [        {          "_userItemDbId": "634cd7e89d34dd31017382e0",          "_relatedItems": {            "_pageSize": 3,            "_list": [              {                "Asset Name": "5SPD.R1.HV.AHU.0002",                "sensor": {                  "_pageSize": 1,                  "_list": [                    {                      "_sourceId": "e3e052f9-0156-11d5-9301-0000863f27ad-00000131",                      "_id": "634ce4999d34dd31017382ef",                      "_metadata": {                        "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                        "_createdAt": 1665983641162,                        "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                        "_updatedAt": 1665983641162                      }                    }                  ],                  "_offset": 0,                  "_total": 1                },                "_id": "634ce4769d34dd31017382ed",                "_metadata": {                  "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                  "_createdAt": 1665983606783,                  "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                  "_updatedAt": 1665983606783                },                "properties": {                  "dtCategory": {                    "val": "HVAC Air Handling Unit"                  },                  "Containing Floor": {                    "val": 1                  }                }              },              {                "Asset Name": "5SPD.R1.HV.AHU.0003",                "sensor": {                  "_pageSize": 1,                  "_list": [                    {                      "_sourceId": "a54052f9-0156-11d5-9301-0000863f27ad-000001454",                      "_id": "634ce4999d34dd31017382f0",                      "_metadata": {                        "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                        "_createdAt": 1665983641163,                        "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                        "_updatedAt": 1665983641163                      }                    }                  ],                  "_offset": 0,                  "_total": 1                },                "_id": "634ce4769d34dd31017382ee",                "_metadata": {                  "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                  "_createdAt": 1665983606783,                  "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                  "_updatedAt": 1665983606783                },                "properties": {                  "dtCategory": {                    "val": "HVAC Air Handling Unit"                  },                  "Containing Floor": {                    "val": 2                  }                }              },              {                "Asset Name": "5SPD.R1.HV.AHU.0004",                "sensor": {                  "_pageSize": 0,                  "_list": [],                  "_offset": 0,                  "_total": 0                },                "_id": "634ce6ac9d34dd31017382f7",                "_metadata": {                  "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                  "_createdAt": 1665984172343,                  "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",                 "_updatedAt": 1665984172343                },                "properties": {                  "dtCategory": {                    "val": "HVAC Air Handling Unit"                  },                  "Containing Floor": {                    "val": 3                  }                }              }            ],            "_offset": 0,            "_total": 3          },          "_id": "634cd7e89d34dd31017382e1",          "_isTip": true,          "_metadata": {            "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",            "_createdAt": 1665980392076,            "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",            "_updatedAt": 1665980392076          },          "_version": 1        }      ],      "_irn": "itemsvc:nameduseritem:634cd7e89d34dd31017382e0",      "_namespaces": [        "Lnt_GglJp74V"      ],      "_nextVersion": 2,      "_shortName": "asset_coll",      "_tipVersion": 1,      "_versionsCount": 1,      "_itemClass": "NamedUserCollection",      "_userItemId": "asset_coll_jPQCU4n096",      "_id": "634cd7e89d34dd31017382e0",      "_metadata": {        "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",        "_createdAt": 1665980392072,        "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",        "_updatedAt": 1665980392072      },      "_kind": "collection"    }  ],  "_time": "62ms"}