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 ?Solution:Jump to solution
@Chinmay Khandelwal Firestore does not directly support a "not equals" (!=) operator for queries, including those on timestamp fields. This is a limitation in Firestore's query capabilities
there is not issue with Date.now() - for the error firebase is not defined ensure the node has -
import { Firestore, DocumentReference, Filter, Timestamp } from "@google-cloud/firestore";
import...9 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 ?
Hey , bro did you found the solution because currently i am also facing the same issue
Processing...
🤖 Assembling the pieces of the puzzle. 🧩 this might take a couple of minutes... beep boop
🤖 AI Response
To assist you effectively with your BuildShip issue, please provide more details about the specific problem you're encountering, such as error messages, the workflow or nodes involved, and any recent changes made. Common issues reported by users include workflows only working in "test" mode but not in production, errors like "NaN is not allowed," and integration problems with platforms like FlutterFlow, such as CORS errors or assertion errors related to API calls. If you're experiencing logging issues or cannot troubleshoot a specific node, submitting an in-app support request is recommended for more targeted assistance. Providing these details will help identify the root cause and guide you to a relevant solution.
🔗 References:
1. https://www.youtube.com/watch?v=FBEdPBKcE8Y
2. https://support.buildship.com/m/1346156561915183124
3. https://support.buildship.com/m/1258652268597612564
4. https://support.buildship.com
5. https://support.buildship.com/c/1148985716651597944?page=4
BuildShip AI Support
i tried using your above solution for filtering documents using a field of date time format using this expression - firebase.firestore.Timestamp.now() but it showing the error saying that firebase is not defined
Solution
@Chinmay Khandelwal Firestore does not directly support a "not equals" (!=) operator for queries, including those on timestamp fields. This is a limitation in Firestore's query capabilities
there is not issue with Date.now() - for the error firebase is not defined ensure the node has -
import { Firestore, DocumentReference, Filter, Timestamp } from "@google-cloud/firestore";
importokay thanku Gaurav for your help