Firestore Collection Group

In addition to being able to query Firestore collections and sub-collections, my company would like to be able to query Collection Groups.

An example use case schema in which we want to see all Users across all Organizations (ie, the Users Collection Group):

Organizations/<org_id>/Users

Currently we need two tables (Organizations, Users) with chained queries and we still only see Users in the context of their Organization.

3 Likes

Hey @kamillamagna, and welcome to the community! Just to make sure I’m understanding correctly, you’re referring to these? (released about a year ago) https://firebase.googleblog.com/2019/06/understanding-collection-group-queries.html

Yeah, I linked to that in my original request.

LOL I did not put 2+2 together there. I'll share this with the team :slight_smile:

1 Like

Just wondering if this made it to the roadmap or if there’s a way to use custom js (https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query)

@chrisattrove this should get released this week :slight_smile:

1 Like

It looks like this feature got released; however, the implementation makes it possible to select only the top-level collections for querying which defeats the purpose of collection group querying. I am excited to use this once I can input the correct sub-collection to collection group query. Any ETA on the fix for this? It seems like a nice short-term fix would be to allow users to type in a custom collection name so we aren’t bound to the ones that retool can find?

Hey @andrewbeckman! You are correct - we're still working the kinks out so we haven't updated the thread yet. We'll update the dropdown to show all subcollections, which, to your point, is literally the whole point of collection group queries :slight_smile: - when that's done I'll update the thread. Ideally this week.

Another thing - we're thinking about adding a raw query editor that will allow you to write raw queries via the Firebase JS SDK. That will help us support batched writes, but also give you the ability to write anything that Retool doesn't quite support yet!

@andrewbeckman this should be fixed now! Let me know if it’s working as expected

Update for the whole topic - you can now query Firebase collection groups in Retool! You can select "query collection group" from the action type dropdown, choose your collection group name, and set other query params like limits.

Hello,

I'm trying to understand how to query some of my data by sub collection groups and coming up short.

My data is structured: users/{userId}/subcollectionGroupName

What I want to do is query all subcollectionGroupName data and display in a table. How can I do this with Retool please?

Hey @HorizonApp!

You should be able to set subcollectionGroupName as the collection in your Firestore query. As mentioned here once you declare an exception for a collection group in Firestore it functions like a top-level collection would for reads so you'll be querying across every collection with the subcollectionGroupName id in your Firestore db.

It looks like Firestore doesn't natively support limiting collection group queries to a particular path at the moment (though there might be some workarounds).

1 Like

@Kabirdas Hi!

Thanks a lot. I can see that working now :smile: