HI,
I use Go to work with my Firebase instance. I inserted a document like this.
firestoreClient.Collection(t.CacheName).Doc(id).Set(t.Context, DataObject{
Id: id,
Url: request.URL.RequestURI(),
ExpireAt: time.Now().Add(time.Hour * 48),
})
In the Firebase web portal, I can see the document and the "ExpireAt" field is correctly recognized as a "timestamp".
But when I try to query the documents using the "ExpireAt" field from the web portal, no document returns. I have tried to use a string and a number to query against that field.
Solved! Go to Solution.
When you try to use a WHERE clause and use the “==” (or “!=”) operator, you don’t get a “timestamp” type available;
…however, if you change to any other operator, you “unlock” the timestamp type.
The Cloud Console shows the same behavior so I can only guess this is expected.
Apparently, you cannot query documents with a field that is exactly (or not exactly) a specific timestamp, however, you can only query documents that have a value greater than, greater than or equal to, less than, etc… a specific timestamp.
For some reason, using a double condition to have the field less than or equal to AND greater than or equal to with the exact timestamp (to emulate the == operator) does not work:
… subtracting a millisecond from the greater than or equal to condition (>=) just makes it work.
In any case, your problem seems to be the first thing I mentioned. I’d suggest you change the operator to any other than “==” or “!=” to “unlock” the timestamp type in the Query Builder.
I’d also suggest that if you’re trying to query a document with a specific timestamp, “wrap” the timestamp between “<” and “>” operators to make it work.
Hi, David,
Could you please provide me with a minimal reproducible example?
First, I want to know how to query by "timestamp" on the Firestore web portal. The portal only allows querying by "string" and "number". If I want to query a field with the type "timestamp", is it simply impossible, or do I need to convert the "timestamp" to a number or a string, and by what rule do I perform that conversion?
Thanks
When you try to use a WHERE clause and use the “==” (or “!=”) operator, you don’t get a “timestamp” type available;
…however, if you change to any other operator, you “unlock” the timestamp type.
The Cloud Console shows the same behavior so I can only guess this is expected.
Apparently, you cannot query documents with a field that is exactly (or not exactly) a specific timestamp, however, you can only query documents that have a value greater than, greater than or equal to, less than, etc… a specific timestamp.
For some reason, using a double condition to have the field less than or equal to AND greater than or equal to with the exact timestamp (to emulate the == operator) does not work:
… subtracting a millisecond from the greater than or equal to condition (>=) just makes it work.
In any case, your problem seems to be the first thing I mentioned. I’d suggest you change the operator to any other than “==” or “!=” to “unlock” the timestamp type in the Query Builder.
I’d also suggest that if you’re trying to query a document with a specific timestamp, “wrap” the timestamp between “<” and “>” operators to make it work.
So, querying with a "timestamp" is unavailable on the filter panel from the "Panel View". I think it is okay. At least, there's one way to query with a timestamp. Thanks.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |