Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: collection group query within collections of a document's subcollections' documents. #3867

Closed
just7mile opened this issue Sep 30, 2020 · 1 comment
Assignees

Comments

@just7mile
Copy link

[REQUIRED] Describe your environment

  • Firebase SDK version: 7.21.1
  • Firebase Product: firestore

[REQUIRED] Describe the problem

With the Run Query we can query within collection group of a document's subcollections, but this is not available in the client SDK. The client SDK allows querying collection group only on the root level.

Steps to reproduce:

For example we have a collection of rootCollection and its documents have subcollection subCollection. Documents of subCollection also have subcollection subSubCollection. It's possible to query collection group subSubCollection across all database, but not just inside rootCollection/someDocId.

Relevant Code:

firebase.firestore().collectionGroup('subSubCollection'); // OK

// collectionGroup does not exist in DocumentReference. 
firebase.firestore().collection('rootCollection').doc('docId').collectionGroup('subSubCollection'); // Error

Is there anything preventing from implementing this in the client SDK?

@wu-hui
Copy link
Contributor

wu-hui commented Oct 2, 2020

Hi @Dzhamshed

Thanks for pointing out the inconsistencies between SDKs and the REST API.

First I want to confirm that it is possible to run collection group queries on sub-collections via REST API, it has a restriction though: there must not be any filters or order-by with the query.

Second, given the restriction above, we will not support this in SDKs, we will re-evaluate this when this restriction is lifted.

Third, there are some workarounds in SDKs that you can do to simulate a collection group query on sub-collections, unfortunately they require you to have some sort of special filed in your documents. For example, you can have a field for parent's collection path in a document, and filter on this field when running collection group queries.

Thank you again!

@wu-hui wu-hui closed this as completed Oct 2, 2020
@firebase firebase locked and limited conversation to collaborators Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants