Avinash Yalgonde
Avinash Yalgonde

Reputation: 111

Apply join like SQL to get data from multiple collections - Firestore

I have a project database setup on Firestore. For some case I just want to pull out data from multiple collections and combine them like SQL. Also we have provision of pagination with filters applied on data. So its like applying where condition and joining multiple collections to get relevant data. Can anybody help me to get this result?

Upvotes: 0

Views: 242

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599591

Firestore read operations get documents from a single collection, or a group of collections of the same name. It has no support for server-side join operations.

The two common workaround for this are:

  1. Load the additional data from your application code, also referred to as a client-side join. This affect performance a bit, but not nearly as much as you may expect - so definitely try and measure performance before ruling it out.
  2. Duplicate the data that you need from the secondary collection. This way you store more data, and your write operations become more complex, but reading the data is fast and simple.

The second solution is also the only way to have conditions on the data from both collections, as there's also no way to query across collections.

While this may all be very unexpected if you come from a background in relational databases, it is actually very common amongst NoSQL solutions and is one of the reasons they can scale so well to massive data sizes.

To learn more, I highly recommend reading NoSQL data modeling and watching Getting to know Cloud Firestore.

Upvotes: 1

Related Questions