All Collections
Tutorials
Using "Distinct" and "Count" within the Object Store.
Using "Distinct" and "Count" within the Object Store.

Learn how to perform grouping in the object store.

Iuri Guedes Emer avatar
Written by Iuri Guedes Emer
Updated over a week ago

The object store is a non-relational database, and therefore, the commands and processes differ from those typically used in relational databases.

In this article, we will show how to perform grouping of identical items within an object store (equivalent to the "distinct" command in relational databases) and also count how many objects are stored.

Distinct

Within the object store component, change the operation to "Aggregate," and in the query, add the following command, replacing "$price" with the field you want to group by:

[{
$group: {_id: null, uniqueValues: {$addToSet: "$price"}}
}]


Executing this operation will result in an output containing only the unique values.

Count

To count the number of records, simply use the following command, in the same way as done above (Operation: Aggregate).

[{
$group: {_id: null, count: { $sum: 1 }}
}]

This operation will return the quantity of records stored in this object store.


Did this answer your question?