Skip to main content
Version: v4.5

findInCollections

readings query in a findInCollections query#

Use the $findInCollections query to look up related items in named user collections—add a readings query object to your $findInCollections query to include telemetry item readings in the response.

The following code example shows a readings query object as part of a $findInCollections query. For more information on readings query objects and their options, see readings query.

Example request

{  "$findInCollections": {    "collectionDesc": {      "_itemClass": "NamedTelemetryCollection"    },    "collectionProject": {      "_userItemId": 1,      "_name": 1    },    "query": {      "dtType": "Temprature Sensor"    },    "options": {      "project": {      "_sourceId": 1    },    "page": {      "_pageSize": 100,      "_offset": 0    },    "sort": {      "_metadata._updatedAt": 1    }  },  "readings": {    "filter": true,      "includeResult": true,      "query": {        "$and": [          {            "temp": {              "$gte": 11            }          },          {            "_ts": {              "$gte": "2021-12-01T09:00:00.000Z"            }          }        ]      },      "options": {        "page": {          "_pageSize": 100,          "_offset": 0        }      },      "as": "sensor_readings"    }  }}

Example response


{  "_list": [    {      "_uri": "/nameduseritems/634cc91c9d34dd31017382d3",      "_name": "Temperature Sensors Collection",      "_tipVersion": 1,      "_itemClass": "NamedTelemetryCollection",      "_userItemId": "tempsensor_2ZoU1RwTKm",      "_tipId": "634cc91c9d34dd31017382d4",      "_versions": [        {          "_userItemDbId": "634cc91c9d34dd31017382d3",          "_relatedItems": {            "_pageSize": 1,            "_list": [              {                "_sourceId": "a2e052a6-9126-21d5-7301-0000863f27ad-3450121",                "_id": "634ccbe19d34dd31017382dc",                "sensor_readings": {                  "_pageSize": 1,                  "_list": [                    {                      "temp": 12,                      "_tsMetadata": {                        "_telItemId": "634ccbe19d34dd31017382dc",                        "_sourceId": "a2e052a6-9126-21d5-7301-0000863f27ad-3450121"                      },                      "_id": "634ccfbb9d34dd31017382dd",                      "_ts": "Tue Oct 11 01:00:24 GMT 2022"                    }                  ],                  "_offset": 0,                  "_total": 1                }              }            ],            "_offset": 0,            "_total": 1          },          "_id": "634cc91c9d34dd31017382d4",          "_isTip": true,          "_metadata": {            "_updatedById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",            "_createdAt": 1665976605041,            "_createdById": "057ce6fd-a306-4bdc-8514-0a45c453f7ec",            "_updatedAt": 1665976605041          },          "_version": 1        }      ],      "_irn": "itemsvc:nameduseritem:634cc91c9d34dd31017382d3",      "_id": "634cc91c9d34dd31017382d3",      "_kind": "collection"    }  ],  "_time": "31ms"}