Does collection group queries get data from all collections with the same name?

后端 未结 1 1369
抹茶落季
抹茶落季 2021-01-16 03:14

I have this Firebase Cloud Firestore schema:

my_db -> users -> uid -> places -> placeId

and

my_db -> places          


        
相关标签:
1条回答
  • 2021-01-16 04:03

    Collection group queries always look at all top-level collections and subcollections with any path at any depth with the name you provide. There is no way to change this behavior. You will need to name your collections differently if you want to limit the scope of the query.

    If you can't change your database structure, you could at least ignore the results from the collections you're not interested in by filtering the documents on the client by looking at the path of the document in the snapshots you receive, and deciding for yourself if you should process that document.

    Another strategy would be to put a boolean field in the documents of each one of your subcollections that does not exist in the top-level collection documents. You can use this field to query only for only the documents in the subcollections.

    0 讨论(0)
提交回复
热议问题