Back

[SOLVED] Use Query by Appwrite correct method

  • 0
  • Web
Ayush
23 Jun, 2023, 21:41

const fetchReviews = useCallback(async (placeId) => { const cleanPlaceId = placeId.replace(/[^a-zA-Z0-9_.-]/g, '').replace(/^[^a-zA-Z]/, ''); const truncatedPlaceId = cleanPlaceId.substring(0, 34); const truncatedPlaceId1 = a${truncatedPlaceId}`; try { const response = await databases.listDocuments( process.env.REACT_APP_DATABASE_ID, process.env.REACT_APP_COLLECTION_ID, Query.equal('coordinates',[truncatedPlaceId1])
);

TypeScript
  const fetchedReviews = response.documents.map((document) => document.review);
  setReviews((prevReviews) => ({
    ...prevReviews,
    [placeId]: fetchedReviews,
  }));
} catch (error) {
  console.error('Error fetching reviews:', error);
}

}, []); ` I don't know what's causing the error below

Error fetching reviews: AppwriteException: Invalid queries: Value must a valid array and Value must be a valid string and no longer than 4096 chars at Client.<anonymous>

TL;DR
The user had an issue with using the correct query method in Appwrite. They were provided with the correct query syntax and were directed to the documentation for further information. The user also received help on fixing an error related to an index not found.
Bouahaza
23 Jun, 2023, 21:47

Try

TypeScript
const response = await databases.listDocuments(
    process.env.REACT_APP_DATABASE_ID,
    process.env.REACT_APP_COLLECTION_ID,
    [
      Query.equal('coordinates',[truncatedPlaceId1])  
    ]  
  );
Ayush
23 Jun, 2023, 21:51

yes thanks error went away

Ayush
23 Jun, 2023, 21:56

hey could you clarify this error this is the new error

Error fetching reviews: AppwriteException: Index not found: coordinates at Client.<anonymous>

Bouahaza
23 Jun, 2023, 21:58

Thinks you use cloud

Bouahaza
23 Jun, 2023, 21:58

You need to create index for equal queries

Bouahaza
23 Jun, 2023, 21:59

You can create index directly via console (website)

Ayush
23 Jun, 2023, 22:05

okay thanks Bouahaza for your so much fast and correct help

Drake
23 Jun, 2023, 22:38

Use Query by Appwrite correct method

Drake
23 Jun, 2023, 22:38

FYI, it's best to use 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

Drake
23 Jun, 2023, 22:39

and FYI, the queries are documented here: https://appwrite.io/docs/databases-queries

Drake
23 Jun, 2023, 22:39

[SOLVED]Use Query by Appwrite correct method

Ayush
23 Jun, 2023, 23:21

okay thanks Steven I will remember this 😊😊

Drake
23 Jun, 2023, 23:22

[SOLVED] Use Query by Appwrite correct method

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