#[SOLVED] Use Query by Appwrite correct method

13 messages · Page 1 of 1 (latest)

opal pawn
#

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])
);

  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>

civic hawk
#

Try

const response = await databases.listDocuments(
    process.env.REACT_APP_DATABASE_ID,
    process.env.REACT_APP_COLLECTION_ID,
    [
      Query.equal('coordinates',[truncatedPlaceId1])  
    ]  
  );
opal pawn
#

yes thanks error went away

#

hey could you clarify this error this is the new error

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

civic hawk
#

Thinks you use cloud

#

You need to create index for equal queries

#

You can create index directly via console (website)

opal pawn
#

okay thanks Bouahaza for your so much fast and correct help

glossy moat
#

Use Query by Appwrite correct method

glossy moat
#

[SOLVED]Use Query by Appwrite correct method

opal pawn
#

okay thanks Steven I will remember this 😊😊