As you know, Cumulocity does not support filtering measurements with user-defined attributes. By the way it is a must for us; Daily we send more than 100,000 measurements to the cloud and we need to filter them. So, I wanted to know what is the best practice for that?
2 Answers
If you take a look at the measurement reference documentation you'll see that you can query measurements by type, time range, source, and valueFragmentType + valueFragmentSeries.
Try to design your measurement data model around these querying possibilities.
Typically fragment type and series describe the measurement value functionally. Type describes the measurement in general.

- 420
- 3
- 9
-
I already know, but your standard attributes is not sufficient for us. Do you have a best practice for my question (without changing the question)? – Parda Aug 02 '19 at 08:38
-
Without knowing more about your particular use case I can't really give more detailed advice – l2p Aug 02 '19 at 09:02
-
I.e. each measurement has an owner (userId). And each user should see his own measurement values on a separate page. – Parda Aug 02 '19 at 09:41
-
Typically measurements are not sent by users but by devices. Then you can allow certain users to see only certain devices and their measurements. See https://cumulocity.com/guides/users-guide/administration/#inventory – l2p Aug 02 '19 at 10:09
-
It's about my particular use case not your typical assumptions. I need to filter measurement by userId, what is the best practice? Please simply mention, if you cannot support such a simple request. – Parda Aug 02 '19 at 10:19
-
If you want advice for your specific use case then tell me about it, otherwise I'll have to go by the typical assumptions. Measurements don't contain the user that created them, so you would have to create the measurements with that user information yourself in a way that the above mentioned queries can resolve them. If any of this has security or billing related implications I cannot recommend this approach though. – l2p Aug 02 '19 at 10:45
-
Please focus on the question. The question is not about creating measurement or security. I asked for a simple best practice for FILTERING the measurement by user-defined-attributes. Is it possible? Or we have to change our platform only because you don't support such simple features? Is it like that you don't have a solution for it and don't want to simply say it? – Parda Aug 02 '19 at 11:52
I think there's not a "Best practice for filtering measurements". You just filter them, doing it as best as you can.
You can achieved this by creating a microservice (https://cumulocity.com/guides/microservice-sdk/introduction/) that can do that filter for you. What this microservice would do is receive a request with the filters (dates, fragmenType, series, device, user id, etc) you need and apply them locally (ex: filter the measurements that c8y return by the he userId)
Then, what you need to is consume it. Here, it's up to you, you can create a plugin in a cockpit based app or an app from scratch.
Hope this helps.

- 238
- 1
- 10
-
Yes, I guess that is actually the only solution. The problem is that, we have to fetch all the data from DB and then filter it, so it is not performant enough. Please let me know if you think there is some other ways. – Parda Aug 05 '19 at 08:27
-
There is also another method to save measurements as managedObject and then we can filter them. But It can be more redundant than using microservice. I hope someone from cumulocity list the possible solutions for that. – Parda Aug 05 '19 at 08:42