Firebase-js-sdk: Collection Group Queries on parent

Created on 18 May 2019  路  1Comment  路  Source: firebase/firebase-js-sdk

Firebase Product: Firestore

I'm glad that we now have collection group queries but I feel like a major use case is not implemented.

I would like to be able to query a collection for documents that contain a particular document in their subcollection.
For example, a VERY common use case would be in a chat app where you want to find any 'chatroom' document containing a particular member in a 'members' subcollection. With the current set up it seems I can only find the 'member' documents in all 'chatroom' subcollections and then hopefully be able to backtrack their parent documents from there. While this is possible it becomes incredibly prohibitive when you cannot filter for a particular timerange or other property on the parent. What if I want only the chatrooms created in the last week? If the user has been active in 10000 chats then I have to retrieve 10000 documents and then query their parent documents.

Am I missing something and this is currently possible? Or will this perhaps be implemented in the future?

firestore

>All comments

Hi! Thanks for writing in. You're not missing anything.

Unfortunately, the feature you're asking for (being able to select members based on properties in the chatroom) requires a join, and that's not something we're planning to add to Firestore, for collection groups or otherwise. If this changes we'll come back here and update.

The way to solve these kinds of problems in Firestore is through denormalization. Copy properties of the parent into the member or maintain side-tables that combine properties of members, chats or otherwise.

Was this page helpful?
0 / 5 - 0 ratings