I am inserting documents into a collection with Firebase using monotonically increasing alphabetically sortable IDs (that are RFC3339-formatted dates). This helps me query the oldest documents and remove them when I reach a certain number.
So my doc IDs look like these strings:
- "2021-05-21T18:00:00Z"
- "2021-05-21T21:00:00Z"
- "2021-05-21T22:00:00Z"
I am using cloud.google.com/go/firestore Go library to retrieve docs with IDs less than (<
) a particular value (then I plan on deleting these docs in a batch operation, e.g. delete docs older than 30 days).
However, the Go package for this returns no results for my query (at least on the Firebase Emulator):
iter := u.DB.Collection("users").Doc(uid).Collection("orders").
Where(firestore.DocumentID, "<", "2020-04-23T02:00:00Z").Documents(ctx)
// iter comes back empty.
I cannot tell if it is a limitation of the product (e.g. __name__
does not support querying with <
or >
) or if it is a shortcoming/unimplemented behavior of the Firebase Emulator.
This question probably should be about why this doesn't work ––but if anyone has suggestions around keeping max N records in a collection in a rotating fashion (like a FIFO queue with a cap) I am interested in hearing as this is why I am trying to use this query.