firebaseunity-game-enginefirebase-realtime-database

Get choosen categories from firebase database


I'm trying to get multiple categories from my firebase database, here is the structure:

category 1 = GCPVN-GCPVQ-GCPVR-GCPVP-GCPUZ-GCPUY-GCPUV-GCPVJ-GCPVM
category 2 = GCW2H-GCW2K-GCW2M-GCW2J-GCWRV-GCWRU-GCWRG-GCW25-GCW27

structure

What I would like to do is to get categories by sorting if their key contains a specified string (for example: "GCPVN").

I don't know if there is a solution using "StartAt", "EndAt" and "EqualsTo".

I'm using Unity.


Solution

  • Firebase Realtime Database does not have an operator that checks for a certain string inside the key of a set of nodes. You can do a prefix match (so keys starting with a specific string) with startAt and endAt, but no contains operation.


    If you want to read all nodes whose key 8starts with* GCPVN, you can do that with:

    FirebaseDatabase.DefaultInstance
            .GetReference("1-1-2025")
            .OrderByKey()
            .StartAt("GCPVN")
            .EndAt("GCPVN~")
    

    Also see the Firebase documentation on sorting and filtering data.


    If your use-case requires a contains operation, you'll need to use a (or an additional) tool that supports that.


    This has been covered quite a few times before, so also see: