#LISTDOCUMENTS isn't working

1 messages · Page 1 of 1 (latest)

gray harness
#

I am facing an issue with querying documents from my Appwrite database. I have a collection where I store appointments, and I'm trying to retrieve all the documents. However, the results are inconsistent: when I change the attribute used in the query, the retrieved information changes, for example, (in my collection the status of my two appointments are "cancelled and pending". But when I request the documents using await databases.listDocuments I get the two documents with status of both cancelled.

digital quarry
gray harness
# digital quarry Please share your code and resulting response

here is a summary of my output documents, In my database both appointments have state=cancelled, but as you can see in the output documents, one of them have state=scheduled.

{
  documents: [
    {
      schedule: '2024-07-12T04:17:41.693+00:00',
      reason: 'hola hola',
      note: null,
      primaryDoctor: 'Leila Cameron',
      status: 'scheduled',
    },
    {
      reason: 'testing',
      note: null,
      primaryDoctor: 'Alex Ramirez',
      status: 'cancelled',
    }
  ],

here is my getrecenappointments function, which its supposed to get the last appointments of my collection

export const getRecentAppointmentsList = async () => {
  try {
      let total = {
        scheduledCount: 0,
        pendingCount: 0,
        cancelledCount: 0,
      }
      const response = await databases.listDocuments("668b68b0002bf0e489c0", "668b691d00044523577b", [Query.isNotNull("$updatedAt")])
      for(let i = 0; i < response.documents.length; i++) {
        if(response.documents[i].status === "scheduled") {
          total.scheduledCount += 1;
        } else if(response.documents[i].status === "pending") {
          total.pendingCount += 1;
        } else if(response.documents[i].status === "cancelled") {
          total.cancelledCount += 1;
        }
      }
      const data = {
        documents: response.documents,
        ...total
      }
      return parseStringify(data);
    } catch (error) {
    console.log(error);
  }
};
digital quarry
gray harness
#

I changed the Query to [Query.contains("status", ["scheduled", "pending", "cancelled"])], but it is still giving me the grong information

digital quarry
digital quarry
#

(keep in mind the default limit is 25 so you'll need to paginate to get more results)

gray harness
#

I tried removing the Queries but then it only returns one document, I have only two documents in my collection for now, without queries it only returns one of those elements but with wrong information

gray harness
# digital quarry What's your code?
export const getRecentAppointmentsList = async () => {
  try {
      let total = {
        scheduledCount: 0,
        pendingCount: 0,
        cancelledCount: 0,
      }
      const response = await databases.listDocuments("668b68b0002bf0e489c0", "668b691d00044523577b");
      for(let i = 0; i < response.documents.length; i++) {
        if(response.documents[i].status === "scheduled") {
          total.scheduledCount += 1;
        } else if(response.documents[i].status === "pending") {
          total.pendingCount += 1;
        } else if(response.documents[i].status === "cancelled") {
          total.cancelledCount += 1;
        }
      }
      const data = {
        documents: response.documents,
        scheduledCount: total.scheduledCount,
        pendingCount: total.pendingCount,
        cancelledCount: total.cancelledCount
      }
      return parseStringify(data);
    } catch (error) {
    console.log(error);
  }
};```
digital quarry
#

Or maybe the response?

gray harness
#

I solved it!, I added a "use server" in my page.tsx and a revalidatePath("/admin"). idk why that solved the problem, thanks for your help!

digital quarry