Back

[SOLVED] Query $createdAt

  • 0
  • Flutter
showmore
1 Apr, 2023, 08:41

DocumentList response = await databases!.listDocuments( databaseId: "*********", collectionId: "********", queries: [ Query.equal("user_phone_no", phoneNo), Query.orderDesc('$createdAt'), ], ); $createdAt show error, how can I query this, any help

TL;DR
Solution: The issue is with the syntax of the query for the `$createdAt` field. To fix it, you need to escape the dollar sign before `$createdAt` by using `'\$createdAt'`. Additionally, make sure you have created an index for the `$createdAt` field. If you're still facing errors, provide screenshots and more information about the error message. Remember to format your queries as an array.
safwan
1 Apr, 2023, 08:51

have you created an index?

showmore
1 Apr, 2023, 08:55

yes, its format error, it show me red

showmore
1 Apr, 2023, 09:23

No the problem is on Query.orderDesc('$createdAt') I tried Query.orderDesc('${createdAt}') flutter consider it as local variable but its from appwrite database ($id, $createdAt, $updatedAt) common fields

safwan
1 Apr, 2023, 09:54

queries should be passed as an array

showmore
1 Apr, 2023, 10:10

only flutter expert answer me pls queries: [ Query.equal("user_phone_no", phoneNo), Query.orderDesc('$createdAt'), ],

showmore
1 Apr, 2023, 10:11

$createdAt shows red error, format error

safwan
1 Apr, 2023, 10:33

what is the error you're getting. show screenshots

safwan
1 Apr, 2023, 10:35

also, show your indexes

Drake
1 Apr, 2023, 14:52

You need to escape the $ like:

Query.orderDesc('\$createdAt')

showmore
4 Apr, 2023, 07:34

Thanks Steven

Musicien
22 Aug, 2023, 00:54

I spent hours on this syntax issue until I read your response. Thanks so much!

Guille
22 Aug, 2023, 02:08

[SOLVED] Query $createdAt

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