collectionGroup within a certain path

后端 未结 2 1159
攒了一身酷
攒了一身酷 2021-01-21 00:50

I\'d like to do a collection group query but within a certain path, meaning that I would like to target collections not only with the collectionId but also with where the collec

相关标签:
2条回答
  • 2021-01-21 01:09

    This is currently not possible with Cloud Firestore. When you perform a collection group query, it will use all of the collections and subcollections with the given name. You are not able to narrow to scope of the query to specific collections.

    What you can do instead is store a field inside the documents in each subcollection that identify which top-level collection they belong to, then use that field to filter your results.

    0 讨论(0)
  • 2021-01-21 01:11

    Now I would like to query for landmarks that are in a city and not get the general ones.

    No, you cannot. Collection group query will return results from all collections or subcollections with the same name, including the general ones. There is no way you can change this.

    The solution for that is to change the name of your collections to be different if you want to limit the scope of your collection group query.

    If you app is in productuon and you cannot change the name of your collections, simply try to ignore the results that you get client side. How can you achieve this, just take a look a the path of the document and see from which collections belong. In this way you can only use the result from the collection you need.

    Another workaround would be to add a new property of type boolean in your collections named isGeneral and set it tu true in the general collection and false in the others. To get only the particular items and not the general once, add to your query a where call:

    whereEqualTo("isGeneral", false);
    
    0 讨论(0)
提交回复
热议问题