0

I could not find any example for this in Unity. I have the following database: enter image description here

Would it be possible to JOIN the leaders and users in one query and retrieve like top 10 based on score?

I want to do the join to be able to display information such as name and photo.

Theoretically, i can retrieve leaders to a list. than retrieve users to a list, than do matching and sorting but this is quite complex operations for a simple task that hopefully can be done with some kind of query.

Dror
  • 1,262
  • 3
  • 21
  • 34

1 Answers1

0

There is no concept of server-side joins in Firebase. You have two options:

  1. Perform the join client-side, i.e. for each leader look up the data for that user with an extra read. While it leads to a lot more code, the performance is not nearly as bad as most developers expect since Firebase pipelines the calls over its existing connection.
  2. Duplicate the relevant data for the users into their leaderboard entries. This makes the write operations more complex, but reading the data becomes trivial. This type of duplication is very common in NoSQL databases, which are often used for scenarios where the read-performance is crucial. If you pick this option, have a look here for some strategies of dealing with keeping the duplicated data up to date. How to write denormalized data in Firebase
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Great, thanks, wish there were Unity code samples instead of JavaScript.. I prefer method 2. It can be become difficult without proper documentation for Unity firebase SDK. – Dror Dec 15 '18 at 19:25
  • If you're having trouble implementing either, post a new question with the [minimal code that reproduces the problem](http://stackoverflow.com/help/mcve). – Frank van Puffelen Dec 15 '18 at 19:40