Queries across Collections or Opened Realms

I am attempting my first iOS app and trying to think about the [best] options for the underlying data model.

I have an active golf competition, with an ObjectId value in all associated collections, named “compId”.

If I was showing the results of a Leaderboard collection, filtered upon compId and sorted as needed, as each player is listed, you could tap a name to expand and show their individual Scores ( a different collection) on each hole, but obviously linked.

I had expected this type of flow / construct:

  1. User logs in

  2. User selects from available / open competitions - this sets the partition key, which would be an ObjectId

  3. With a comp open, either add new scores (for himself or others) or view the Leaderboard

  4. As iOS app, this Leaderboard would be a TableView

How do I approach this scenario?

  • Do I need to open multiple Realms, per collection?

  • If I only need to open 1, i.e. Leaderboard, can I still query into the other?

  • Would querying across Realms / collections, need extra Realm(s) to be opened?

  • Or is this terrible modelling…???

Leaderboard viewers are not going to look at / expand EVERY player’s scores, in fact it expect only a few players as they are looking at any time. Then return in 10 mins time. Or similar. To ensure the most efficient data usage, how do you query the Scores only when a player has been tapped?

I have read a couple published articles around partitioning by @Andrew_Morgan (RChat Data Design and “Realm Partitioning Strategies”).

Why is there only a single partition key, i.e. 1 attribute / field across ALL collections? Not 1 per collection?

I had starting thinking about the above design structure, and perhaps thought:

  • Once a User has logged in, 1 view would show all the comps (compId) they are registered to. The partition key here would be userId.
  • When a comp is selected, different views to either enter scores or show leaderboard, but both based upon compId, which would be the partition key.

It would seem this isn’t possible? Unless I incorporate the key=value strategy explained by Andrew. This seems so limiting (though I am sure there was / is a rationale…)