Query for data and sorting by collection order

This is my current code:
var mycollection = ( await wixData.query( ‘Stores/Collections’ )
.eq( “name” , “items” )
.find()
).items[ 0 ]

const products = await wixData.query( “Stores/Products” )
.include( “collections” )
.hasSome( “collections” , mycollection._id)
.find()
how can I sort for the order in my items collection?, currently the order is unknown and seems quite random

1 Like

How about items.sort(fn) to change the element order?

Sure, but where can I get the “items” collection order?

@shizts
Something like:
var mycollection = ( await wixData.query( ‘Stores/Collections’ )
.eq( “name” , “items” )
.find()
).items.sort(fn)[0]

you need to provide the sorting function fn for array items.

@ayleung66 I want to set their order by the order I set in the collection UI
Where can I find their order in the DB?

@shizts Compare the two element by creation date. If you have a random order, that is your own problem.

Bump