Wixdata Query Fails When .ascending and .distinct are different types

Hi all,
I am having a problem where my query produces an internal error whenever I sort with .ascending a field that is type number and run with .distinct for a field that is a string. A simple example is:

   wixData.query("DB") 
    .ascending('index') 
    .distinct('itemName') 
    .then( (res) => { 

let results = res.items;
console.log("results = "+ results);
})

Running this produces: " WDE0053: Internal wixData error: Unknown error. "

If I change the field in ascending so it is the same type as distinct, it works fine. I really need my results to come back in order because they are going to be put together in a concatenated object that will display content.

Please help!

So don’t use distinct(). You find() and omit the duplicate results. Something like:

 wixData.query("DB")
        .ascending('index')
        .limit(1000)
        .find()
        .then( (res) => {
               let results = res.items.map(e => e.itemName);
              results = results.filter((e, index) => results.indexOf(e) === index);
               console.log(results);
        })

Apparently you can’t sort distinct() based on other fields (but it’s not documented)

Thanks, that will work well. Also, it does work with aggregate as well, apparently just not .distinct, in case anyone else runs into this problem