Simple filter by date in a Firestore query
Hey everyone,
I just started trying BuildShip and I'm already stuck on something that should be very easy, however I can't find the right documentation.
I made a Firebase collection query, I tested it without any filter and it does return the elements I expect. However I can't figure out the correct syntax of the filter to only return elements where "NextOccurence" property is before the current date and time.
{
field: "NextOccurence",
operator: "<=",
value: Date.now(),
}
Can you help ?3 Replies
AI Support Bot Information
<@427568565680340992> you can react on the relevant answer (message) with a ✅ in this thread when you think it has been solved, by the bot or by a human!
Anyone can react on this message with a ❌ if the GPT bot is unhelpful or hallucinating answers.
Please note: Team members will review and answer the questions on best efforts basis.
AI Response
It seems like you're attempting to filter a Firebase collection to return elements where the "NextOccurence" field is before the current date and time. The filter you are providing has the right idea but it's possible that
Date.now()
needs to be handled differently when dealing with Firebase queries.
In Firebase, dates are typically stored as timestamp objects, so you may need to ensure that the value
is compatible with Firebase's timestamp format.
Here's an example of how you might adjust it:
If you are using Firestore, consider using firebase.firestore.Timestamp.now()
instead of Date.now()
to ensure compatibility.
For further guidance, you might want to review Firebase's documentation on querying and working with dates. If you're still having trouble, it could be helpful to review your Firestore rules and data structure to ensure everything aligns as expected.
You can refer to documentation on Firebase querying here: Firebase Firestore Queries and Timestamp in Firestore.
If you have specific code or configuration from your setup, feel free to share more details for more tailored assistance.
BuildShip AI Support
I'd rather talk to people than a bot 😕
The first solution returns an empty list.
The second solution generates an error : "firebase is not defined"
So I made progress : I used the following filter :
{ field: "NextOccurence", operator: "!=", value: Math.round(new Date()/1000) }and it returns the whole colection, which is correct. However, replacing '!=' with '<' or with '>' returns an empty array. What is the correct way ?