0

I have these collections:

users/portfolios/rents/events

How could I find events with title Lunch?

I need to search for all users, portfolios, rents and events.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Dani
  • 3,128
  • 2
  • 43
  • 91

1 Answers1

2

If you want to query across all events collections in your entire database, you'll want to use a so-called Collection Group Query.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • In those examples I see we always select a specific document for the cities collection. What about if I'm interested in all documents? Do I need to create a composite index as explained here? https://firebase.blog/posts/2019/06/understanding-collection-group-queries – Dani Aug 11 '22 at 22:48
  • I'm not sure what you mean by that first part, but: yes, you always need to explicitly create the index required for a collection group query, as auto-generated indexes are always specific for a collection (not across all collections of the same name). – Frank van Puffelen Aug 11 '22 at 23:03
  • I mean if that's necessary to perform the query correctly – Dani Aug 12 '22 at 07:47
  • Also, in terms of performance and probably plan limitation, would it be better to move the events to a separated collection outside of users? So I would have for each event userId, porfolioId and rentsId as well – Dani Aug 12 '22 at 12:58
  • I'm going to open a separate question for this. Thanks for the original answer – Dani Aug 12 '22 at 13:22
  • https://stackoverflow.com/questions/73335166/firebase-performance-vs-plan-quota-limitations – Dani Aug 12 '22 at 13:46