Firestore get random document with where condition

I agree with Frank, the link has everything you need. You can chain the where conditions.

After following the steps, you can query like:

Firestore.firestore().collection("quotes")
    .whereField("categories", arrayContainsAny: ['change'])
    .whereField("random", isGreaterThanOrEqualTo: random)
    .limit(to: 25)

edit ahhh I see your point. I would work around this issue by querying again.

  • if the result is less than what's needed (25) run another query, something like
Firestore.firestore().collection("quotes")
    .whereField("categories", arrayContainsAny: ['change'])
    .whereField("random", isLessThan: random)
    .limit(to: 25)

You can then store some of the results of both queries to get your 25