Back

Query Integeration Help

  • 0
  • Web
Shubham
28 Aug, 2023, 15:51

I have a collection that has attribute named ids of type arrays , in ids some id will be store that will belong to it , i want to query this collection such that only that documents fetch in which any specific id containes in ids attribute , i will paas this id in input , how will i do that in react.

TL;DR
User is seeking help with integrating a query in their code. They shared a GitHub issue discussing the possibility of using `Query.search` but are unsure if it is officially supported. They mention that their collection has the correct permissions and indexing. They shared their code and mention that it's not working. They ask for assistance in querying their collection to fetch only the documents that contain a specific ID in the 'ids' attribute. There is a suggestion to use `Query.equal('ids', ['id1', 'id2', ...])` and another suggestion to create a separate field named 'search' with a 'fullText' index. There
Binyamin
28 Aug, 2023, 15:53

You can achieve that by creating another field named search and add fullText index to it

Binyamin
28 Aug, 2023, 15:53

Then add all the ID's to that field seperate by space.

Guille
28 Aug, 2023, 15:55

If I understood well you need to create a key index and use Query.equal('ids' ['id1', 'id2', '...'])

Guille
28 Aug, 2023, 15:55

@Binyamin Why you prefer fullText? 🤔

Binyamin
28 Aug, 2023, 15:56

Because I though he also liked to perform a search to find only one ID

Binyamin
28 Aug, 2023, 15:57

If the match looking is for all the IDs together then your solution is the right one.

Guille
28 Aug, 2023, 15:58

Yes, the description is not very clear, lets wait until he clarify what he is looking for

Shubham
28 Aug, 2023, 16:04
TypeScript
  "title": String ,
  "ids": Array[String],
  amount: Int
)```
Shubham
28 Aug, 2023, 16:04

so when i pass any id in function , all document that contains this id in ids array should get

Guille
28 Aug, 2023, 16:06
TypeScript
const queries = [Query.equal('ids', [...])]
const response = await databases.listDocuments('DATABASE_ID', 'COLLECTION_ID', queries);

This is what you should do with the JS SDK

Shubham
28 Aug, 2023, 18:09

its not working

Shubham
28 Aug, 2023, 18:10
TypeScript
  
  try {
    const queries = [Query.equal('ids', [id])]
    return database.listDocuments(databaseID, 
      collectionId,
      queries
      );
  } catch (e) {
    console.error(e.message);
  }
};```
Guille
28 Aug, 2023, 21:10

Do you get any error, or you just get an empty array?

Guille
28 Aug, 2023, 21:10

Does your collection or document have the correct permission?

Shubham
29 Aug, 2023, 10:01

i got empty array

Shubham
29 Aug, 2023, 10:02

My collection has proper permission , and indexing also

Guille
29 Aug, 2023, 21:14
Guille
29 Aug, 2023, 21:15

it seems like is not officially supported however the last comment says you can use Query.search

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