-1

How I can do join with Firestore in my Android application?

my tables in this Picture

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Joining on IDs is a paradigm commonly seen in relational databases, such as MySQL. In NoSQL databases, such as MongoDB or Firestore, you store the whole document. In the most extreme case, imagine you have a rendered page, you store all used raw data. More real-life scenario would be to break it down into smaller documents for reusability and to save bandwidth. That being said, you can still do the join if you want. You just need to download these 3 documents separately with `where` queries and then transform the objects locally. – Arturs Vancans Oct 15 '21 at 14:10

1 Answers1

2

What you're trying to achieve is actually a JOIN, which is currently not supported by Cloud Firestore.

Queries in Firestore are shallow, meaning that they can only return documents from the collection that the query is run against. If you need to get documents from two collections, you'll have to perform two queries and combine the result on the client.

There is an alternative solution, which is called denormalization. This means that you can create another collection that should contain data from both collections. In this way, you can perform a single query against this new collection. There is nothing to worry about this approach, as it's a common practice when it comes to NoSQL databases.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193