Back

querying 2 attributes at a time

  • 0
  • Databases
  • Web
sai pranay
10 Jun, 2023, 16:00
TypeScript
    if (keyword) {
      setLoading(true);
      databases
        .listDocuments(
          import.meta.env.VITE_PUBLIC_DATABASE_ID,
          import.meta.env.VITE_PUBLIC_COLLECTION_ID,
          [
            Query.search("title", keyword),
            Query.orderDesc("$createdAt"),
          ]
        )
        .then((response) => {
          setCrafts(response.documents);
          console.log(response.documents);
        })
        .catch((error) => {
          console.error("Failed to fetch user crafts:", error);
        });
      setLoading(false);
    }
  }, [keyword]);```

I have 2 different attributes title, description 
so how i can query both at the same time
TL;DR
It seems that the user wants to query two attributes at the same time. Currently, this is not supported. However, a possible workaround is to create a new attribute that combines the text from both attributes and use that in the query. Here is an example of how you can modify your code to include the new attribute: ```useEffect(() => { if (keyword) { setLoading(true); databases .listDocuments( import.meta.env.VITE_PUBLIC_DATABASE_ID, import.meta.env.VITE_PUBLIC_COLLECTION_ID, [ Query.search("newAttribute", keyword), Query.orderDesc("$createdAt"), ]
Drake
10 Jun, 2023, 16:36

It sounds like you want to have a logical OR which isn't supported at the moment. Make sure to 👍 this issue: https://github.com/appwrite/appwrite/issues/2740

I would recommend creating an attribute containing all the text you want to search across and then use that in your query

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