Search code examples
javagoogle-cloud-firestoreepoch

Cloud firestore get all documents between two ids of documents


I have a collection with all document ids as epochtime(1613728796). Each of these documents contains up to 50 fields in it. I wanted to query set of documents between specific timing. How I can query based on document's uid?

Query query = db.collection("my-collection").whereGreaterThan("uid", "1613728796")

Solution

  • Try this:

    Query query = db.collection("my-collection").whereGreaterThan("__name__", "1613728796").whereLessThan("__name__", "1613728796")
    

    Replace the above epoch times with the correct ones.

    If that doesn't work, try replacing "__name" with FieldPath.documentId() or FieldPath.documentId