Returning count results

#1

For results that need to be summary counts for a type (i.e. how many machines are at this location), what is the best way to do so? FetchCount? Metrics?

0 Likes

#2

You can use the Persistable.fetchCount API and provide a FetchFilterSpec with a filter. For example:

Locale.fetchCount({filter: Filter.eq('language', 'en')});
// 2
0 Likes

#3

Sounds more like an evaluate call to me, like the following:
MyType.evaluate({projection:"location, count()", group:"location"})

0 Likes

#4

It depends on what information you want.

To find the number of machines at a specific location, you would use fetchCount:

Machine.fetchCount({ filter: Filter.eq('location', 'some_location_id') });

but to find the number of machines at each location, you would use evaluate:

Machine.evaluate({ projection: 'location, count()', group: 'location' });
0 Likes