ManageObject c8y_IsDevice List not getting as expected after applying orderby filter

Hello,

I am calling “inventory/managedObjects” endpoint, to get the list of “c8y_IsDevice”.

The list I am receiving is as expected but whenever I apply the orderby filter it is not coming as expected.

I am retrieving the list by passing query like.

 "query":'$filter= has(c8y_IsDevice) $orderby=id desc'

and also use below query

q=$orderby=id desc

I have created few devices with rest API & few with the SDK both devices structure are same, but the only difference is the owner. If I am fetching an all devices which are coming with two groups, one with owner of user (Rest API) & other with micro service name (SDK),

The preference is been giving to the group of the owner of user & then to SDK.

What I am expecting is to fetch the all devices with order by id regardless of owner.

Can you please help me to achieve the same?.

What tenant is involved here?

Hi Ashwin,

the ID of an object/device is not guaranteed to be in sequence.
Cumulocity is using multiple core nodes and each node holds a bucket of new IDs.
Depending on which core is hit for device creation the ID is taken from this bucket.

Hence ordering by ID does not guarantee to return a list of objects/devices which are ordered by creationTime.
If that is your goal I would suggest to order by creationTime.date instead.

Regards, Kai



Kai Sieben

2 Likes

Ordering by ID compares the IDs as strings not as numbers as you might expect. For example “173200” > “17247200”. Other properties like owner are not considered in this sorting.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.