I am trying to get all the second order documents, whose first order paths are unknown(variable). I mean:
getDocs(query(collection(db, "users", unknownCities, unknownSchools), where("gender","==", "female") ))
where users
is a collection, unknownCities
are the documents, unknownSchools
are the collections, and then there are documents named as userIds
with fields including gender. I mean like the rules section, where there is {path=**}
usage.
Is it possible in Firebase?
Firestore doesn't have the ability to wildcard collection or subcollection names for queries. You need to know those exact names if you want to query the collection. Also, you can only query one collection at a time (except for collection group queries which let you query all collections of the same name).
At best, if you are willing to write code using the backend SDK (and not the web and mobile client SDKs as you are now), you can first list collections or subcollections, then query each one individually.
But if you really need to query across collections whose names you don't know ahead of time, using the web client SDK, it sounds like what you actually need is to restructure your data to put all the relevant documents into subcollections of the same name so you can use a collection group query.