[SOLVED] Moralis Database Querying

Hello,
Been struggling with querying necessary data from DB.
I have a table where every time someone bids on a listing, bid data is synced to a table.
Every row includes a ListingID. If two people bid on the same Listing it will have two rows with the same ListingID.

My goal:
I want to get the most recent bids by createdAt.
I want to get the top 5 ListingIDs with the most bids. (By row count)

Thanks.

You can do a constraint of query.descending('createdAt').

You can do something like:

const pipeline = [{ sortByCount: '$listingID' }];

const result = await query.aggregate(pipeline);
1 Like