Back

[SOLVED] Python list_documents Query syntax help.

  • 0
  • Databases
Lexqam
8 Mar, 2023, 00:52

Hi everyone, I have a pretty simple question regarding how to format the syntax for specifying a query to order the documents by the 'lastUpdated' attribute in a python call for the list_documents function. I tried looking through the docs and online for an example, but didn't have much luck. Here is snippet of my (incorrect) code: databases.list_documents('db_id', 'col_id', query=query.orderDesc("$createdAt")). Any suggestion on how I can fix the function argument to query as intended would be great. Thanks!

TL;DR
The user was having trouble with the syntax for specifying a query in the `list_documents` function in Python. They were using the parameter name `query` incorrectly and passing a single query instead of an array. The correct syntax is to use the parameter name `queries` and pass an array of queries. The user also received tips on formatting code using backticks.
Drake
8 Mar, 2023, 01:09

If you look at the function signature for list_documents() (https://github.com/appwrite/sdk-for-python/blob/7ded6e207b0e0b63540127a4937a22856b1bb434/appwrite/services/databases.py#L556), you'll see the parameter name is queries so you can't use query as the keyword. Secondly, the docs (https://appwrite.io/docs/server/databases?sdk=python-default#databasesListDocuments) mention queries is an array, so you have to pass an array rather than a single query.

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

Lexqam
8 Mar, 2023, 01:19

Thank you so much for the links and tips to format code nicer. It is much appreciated, Steven!

Drake
8 Mar, 2023, 01:32

[SOLVED] Python list_documents Query syntax help.

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