Back

Documents count returned on listDocument query is always 0

  • 0
  • Web
  • Cloud
amitrochates
13 Mar, 2025, 06:39

Hi, I'm trying to retrieve character documents which have an attribute "userId" from a query, but the response is always an empty document.

TypeScript
const response = await databases.listDocuments(
        process.env.APPWRITE_DATABASE_ID,
      process.env.APPWRITE_CHARACTER_COLLECTION_ID,
        [
        Query.equal('userId', userId),
        // Query.select(["characterId"])
        ]
    )
    if (response && response.documents) {
        log(response)
        return {
          success: true,
          response,
          total: response.total
        };
      } else {
        return {
          success: false,
          message: "Received response in unexpected format",
          data: response
        };
      }

Here are some things I've checked - ✅ Document exists with correct userId. ✅ Collection has permission for all users. ✅ collection has an attribute named userId which is also made an index. ✅ function executes, payload is recieved correctly.

Any help is appreciated.

TL;DR
Issue: Query always returns a document count of 0 even when there are matching documents. Solution: Double-check the equality condition in Query.equal to ensure it matches the userId format. Check if userId is stored consistently in the database.
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