Skip to content
Back

limit - Syntax error

  • 0
  • Self Hosted
  • Databases
A
5 Dec, 2024, 12:20

Hi! I am changing all my functions from V 1.4.13 to V 1.6.0, using python. I got the following error when using limit:

Fetching documents with queries: ['equal("Status", "Existing")'] Total documents fetched: 0 No documents fetched. Error fetching documents: Invalid query: Syntax error.

TypeScript
def fetch_existing_documents(
    databases: Databases, database_id: str, collection_id: str, context: Any
) -> List[Dict[str, Any]]:
    documents: List[Dict[str, Any]] = []
    last_document_id: str = None
    while True:
        queries = ['equal("Status", "Existing")']
        if last_document_id:
            queries.append(
                f'cursorAfter("{last_document_id}")'
            )

        try:

            context.log(f"Fetching documents with queries: {queries}")
            response = databases.list_documents(
                database_id=database_id,
                collection_id=collection_id,
                queries=queries,  # Exclude limit for now
            )

            if isinstance(response, dict) and "documents" in response:
                fetched_documents = response.get("documents", [])
                if not fetched_documents:
                    context.log("No more documents to fetch.")
                    break

                documents.extend(fetched_documents)

                last_document_id = fetched_documents[-1]["$id"]
            else:
                context.error(f"Unexpected response: {response}")
                break

        except Exception as e:
            context.error(f"Error fetching documents: {e}")
            break

    context.log(f"Total documents fetched: {len(documents)}")
    return documents

On the photo, you can see the code snippet that works, but I get only 25 files. Do you have any idea how to solve this problem?

TL;DR
Developers are encountering a syntax error when using the `limit` function in their Python script. The error occurs when fetching documents with queries and restricts the number of fetched documents to zero. The current code snippet provided does not include the `limit` parameter, leading to limited document retrieval (only first 25 documents retrieved). Solution: To resolve the issue and retrieve all existing documents, developers can include the `limit` parameter in the `queries` list, specifying the desired number of documents to fetch. By adding `limit(100)` to the list of queries, for example, developers can fetch up to 100 documents matching the specified
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