Back

Get the lastest number from string attribute

  • 0
  • Self Hosted
  • Databases
  • Web
Suiii
23 Sep, 2024, 03:27

I have client table whcih contains code, was initially interger field, but since it doesn't support full searching. I need to change to string and store it.

But when I try to get the last order number. it doesn't return the correct biggest number. any possible solution or workaround for this

TypeScript
const promise: any = await db.clients.list([
    Query.orderDesc("code"),
    Query.limit(1),
  ])
TL;DR
Developers need to get the latest number from a string attribute in a client table. Changing the integer field to a string attribute has caused issues in returning the correct biggest number. A solution could be to ensure proper sorting in the query to get the desired result. The code snippet provided looks for the last code in descending order and limits the result to 1.
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