How do you execute a query that filters based on a timestamp field in firebase?
Equivalently, what must I fill the ... in:
const q = query(ref, where("time", "<", ...));
so as to filter by a the current date (for example)?
Timestamp.now() (Timestamp object)?new Date() (Date object)?Date.now() (Time in milliseconds)?Math.round(Date.now()/1000) (Time in seconds)?I am trying to make a collection query based on the timestamp field of the documents. i.e.
where("next_spaced_revise", "<", ...)
I am using react-hooks-firebase, so make this query via:
const [values, loading, error] = useCollectionData(q);
I am getting a very erroneous behaviour that I am struggling to debug. What happens is that the react component (which the above hook is in) keeps on getting mounted and unmounted. When I place a console.log within preamble code of the JSX component, it gets called over and over.
This behaviour also happens when I don't use react-hooks-firebase and instead use the promises of vanilla firebase getDocs
I have found one error message, which seems to reflect the mentioned behaviour of mounting and unmounting:
Error message Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render
After more investigation, I believe this behaviour occurs whenever an incorrectly constructed query is made. Hence, why I believe that this boils down to getting the correct term to fill ... in where("next_spaced_revise", "<", ...)
Please note that what I called "time" in my example corresponds to "next_spaced_revise"