Skip to content
Back

document ordering advice

  • 0
  • Databases
  • Cloud
Brinamite
29 Mar, 2025, 10:18

Dear all, I have a query that fetches all records from a collection. Now, these records have a Featured Expiry Timestamp, that marks the date when their 'pro' status expires. Now, I want to fetch the list of records ordered by the expiry timestamp ascending, so that those which are expiring soon will be at the top.

simply doing a Query.orderAsc('timestamp') will also fetch those which have their pro status expired. I just want the ones expiring soon to feature first.

Of course, Query.greaterThan('timestamp', Date.now().toString()) will not work in my scenario since I still want the expired ones to feature after the ones with pro status

My idea is to do these 2 queries each time and merge the results, however, I was wondering if there is a more efficient way. However, it might affect my pagination badly.

What is the best way to approach this?

TL;DR
Order records by ascending expiry timestamp, prioritizing upcoming expiration dates. Consider merging results from two queries while keeping pagination in mind. This approach balances efficiency and accuracy.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more