#Appwrite Web Client Query isn't working as expected

1 messages · Page 1 of 1 (latest)

harsh briar
#

I'm trying to wrap my head around using appwrite's queries but some work while others completely fail. For example, if I create an index of type text on an attribute that accepts strings, I can use the Query.search('test') and that works but Query.endsWith('est') fails with 400 status code.

But most concerning is not being able to query the built-in $createdAt attribute. I've created an index for it and have the following code:

    Query.greaterThanEqual('$createdAt', Date.now() - 604800000),
  ])```
 I get this error
glossy cove
#

For the endsWith() method you'll need to provide the attribute name as the first argument and the search string as second

databases.listDocuments(dbId, collectionId, [
    Query.endsWith('full_name', 'est'),
  ]);

For time compering you'll need to send JavaScript date formatted as ISO string as such


const searchDate = new Date(new Date()-604800000).toISOString();

databases.listDocuments(dbId, collectionId, [
    Query.greaterThanEqual('$createdAt', searchDate),
  ]);

You can read more about queries here: https://appwrite.io/docs/queries#query-class

harsh briar
#

Ah thanks for such a quick response. I'll try the date query you provided

glossy cove
#

👍

harsh briar
#

And my fault on the code snippet for endsWith, a copy/paste issue. I do have the attribute as the first argument

#
databases.listDocuments(dbId, tradeCollectionId, [
    Query.endsWith('security_type', '2023'),
  ]);
}
glossy cove
harsh briar
glossy cove
#

What's security_type type?

harsh briar
#

the type is string

#

and formatted as enum

#

and the index type is key I also tried index type of FullText

glossy cove
harsh briar
#

yes, but my UI doesn't have that dropdown? upcoming changes? 😄

glossy cove
#

😄

#

What version of Appwrite you're using?

harsh briar
#

appwrite cloud

glossy cove
#

Ohh then yes, the cloud is on 1.1.2

harsh briar
#

Okay. Is that the reason for query issue? Should I downgrade my project's appwrite package?

glossy cove
#

The compatible one is 10.1.0

#

But I don't think this is the problem
You can try it I'll check something

#

Actually you're correct.
The endsWith was added in version 1.3.0 so it's not available in the cloud yet

harsh briar
#

Ah got it. Cool, I'll downgrade. Thanks!! Is there anywhere that shows that compatibility list? I might've missed it

glossy cove