Firestore query with datetimes and timestamps

Continuing the discussion from Unofficial Anvil Firebase Integration v0.1🔥:

Is there a way to deal with timestamps in queries?

I have a timestamp I have purposely set two days in advance (July 13th). I am listening for anything past the current time that is updated, but that is returning nothing on update.

Here is the code:

def setup_listener(self,status):
  collection = firestore.collection(firestore.db,"customers")
  query = firestore.where("status","==",status)
  q = firestore.query(collection,[query,firestore.where("created",">",datetime.now())]) # this version works -> firestore.query(collection,[query])
  self.listener = firestore.listen_to_docs(q,self._set_documents)

So it will fire the self._set_documents when I don’t use the created condition, but when it is included.

Is there an obvious mistake I am making?

Hi @anthonys,

the query looks good to me, datetime object are serialized automatically.

can you share a screenshot of th document you need to query?
Also it could be possible that you need an index for this listener → check the browser console if there is a log with “this query requires an index” or something like that.

1 Like

You are 1000% right about indexing. Thank you, Mark.

Sometimes it doesn’t matter how much documentation and videos you go through. Making the mistake is the only way to learn.

Really appreciate it!

1 Like

I know this feeling well – the basic video tutorials for firebase are fantastic… the advance ones, not so much :frowning:

1 Like