Find distinct values in DB

Hi guys,
What’s the best way to find distinct values of a certain field in a database collection.
Let’s say I have a field key ‘value’ with the values: 1,2,2,2,3,4 and I wish to get [1,2,3,4] what should I do? I can run some JavaScript on the query results to find the unique values, but I’m wondering if there’s any way to do it with direct DB query?

Thanks,
J.D.

Hi J.D.,

What I do is run an aggregate query grouping by that field:

wixData.aggregate("CollectionName")
    .group(FieldName)
    .count()
    .ascending("_id")
    .run()
    .then((results) => {
        console.log(results);
    })

Thanks, @tony-brunsman .
I’ll try it and see.