Back

How to listDocuments using or query by document ids

  • 0
  • Self Hosted
  • Databases
Marc
29 May, 2024, 09:17

I'm encountering a problem when executing a query to get all the documents for an array of id's in Java.

This is my the query I'm passing:

TypeScript
                eventIds.stream()
                        .map(eventId -> Query.Companion.equal("$id", eventId.toString()))
                        .toList()
        ));```

When executing this query using databases.listDocuments() I'm getting the following error:
```Invalid query: Attribute not found in schema: _uid```

It seems like it's converting the $ character to _u in the query.
If I try to do the same with an attribute I set myself, let's say the attribute "name" everything works as expected.
But I want to select the documents by their documentId and not by an attribute I set myself.

Appreciate any help, I'm sure it's just a little mistake I'm making here.

This is my Java code for the listDocuments():
```databases.listDocuments(
                    "event-db",
                    "event",
                    queries,
                    new CoroutineCallback<>((result, error) -> {
                        if (error != null) {
                            log.error(error.getMessage());
                        } else {
                            assert result != null;
                            log.info("{} Events found", result.getDocuments().size());
                            result.getDocuments().forEach(document -> events.add(appwriteDataToEvent(document)));
                        }

                        latch.countDown();
                    }));```
TL;DR
Developers are encountering an error when trying to execute a query to get all documents for an array of IDs in Java. The issue lies in how the query is being structured, causing an "Attribute not found in schema: _uid" error. Only documents with manually set attributes work, not the auto-generated document IDs. A possible solution is to revise the query structure to ensure proper character conversion when querying by document IDs.
Meldiron
29 May, 2024, 09:29

Hey there 👋 Code looks good to me. What Appwrite version are you running?

Marc
29 May, 2024, 09:33

I'm on version 1.5.5 self hosted

Meldiron
29 May, 2024, 09:46

Hmm honestly, I am not sure what could be the issue. Let me cc @Steven for this one

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