To get the list of documents, filtered by datetime an intuitive method would be something like this:
# get datetime before an hour
hour_ago = datetime.now()-timedelta(hours=1)
databases = Databases(client)
doclist = await databases.list_documents(
"databaseID", # database_id
"collectionID", # collection_id
[
# queries
Query.greaterThan("$updatedAt", hour_ago),
]);
But this results in an empty list. The issue I found was its because of how the value of datetime is parsed. The datetime is simply set str(datetime) to query, but the resulting string is invalid for filtering the documents.
Workaround
The way I solved this is by using the query string by myself.
# get datetime before an hour
hour_ago = datetime.utcnow()-timedelta(hours=1). # requires utc datetime
databases = Databases(client)
doclist = await databases.list_documents(
"databaseID",
"collectionID",
[
f'greaterThan("$updatedAt", ["{hour_ago.isoformat()}"])',
]);
👍 Expected behavior
It should result in a list with appropriately filtered documents, but it doesn't.
👎 Actual Behavior
It either results in all of the documents or none at all depending on the filter greaterThan or lessThan used.
🎲 Appwrite version
Version 0.10.x
💻 Operating system
Linux
🧱 Your Environment
No response
👀 Have you spent some time to check if this issue has been raised before?
👟 Reproduction steps
To get the list of documents, filtered by datetime an intuitive method would be something like this:
But this results in an empty list. The issue I found was its because of how the value of datetime is parsed. The datetime is simply set
str(datetime)
to query, but the resulting string is invalid for filtering the documents.Workaround
The way I solved this is by using the query string by myself.
👍 Expected behavior
It should result in a list with appropriately filtered documents, but it doesn't.
👎 Actual Behavior
It either results in all of the documents or none at all depending on the filter
greaterThan
orlessThan
used.🎲 Appwrite version
Version 0.10.x
💻 Operating system
Linux
🧱 Your Environment
No response
👀 Have you spent some time to check if this issue has been raised before?
🏢 Have you read the Code of Conduct?