0

I'm working on an iOS workout split app with firebase RT database as the backend. At the moment, I'm storing the data on all the workouts like this is firebase:

{
  "DuGjwAxKwScYFiWK4xx1IsATfsC2" : {
    "splits" : {
      "Test-Split" : {
        "day 1" : {
          "-MhjCRcr8Wv7HrIF8Ico" : {
            "Exercise Name" : "Curls",
            "Is Timed" : false,
            "Reps or Secs" : "12",
            "Sets" : "4"
          },
        }
      },
      "Test-Split-2" : {
        "day 1" : {
          "-MhjC_FAIrYLD907KmXY" : {
            "Exercise Name" : "Squats",
            "Is Timed" : false,
            "Reps or Secs" : "12",
            "Sets" : "4"
          }
        }
      }
    }
  },

What I'm looking to do at the moment is pull just the names of the splits, so that a user can select which split they want to run. In the above example, the split names are Test-Split and Test-Split-2. The trouble is, they don't have any kind of key associated with them. I can pull a snapshot that will give me all the data downstream of "splits", but how do I just pull the split names?

Thanks!

  • Looks like it could work. There he got a lot of people telling him his data was overly nested. Does my structure here have a similar problem? I'm still very new to firebase so I don't want to get into any bad habits. If it does, what would be a better way to structure this database? – Nick Mcmullan Aug 22 '21 at 19:38
  • 2
    If you only want to get the keys (`Test-Split`, `Test-Split-2`) and not the underlying values, the only way to do so is through the REST API and its `shallow=true` parameter (see https://stackoverflow.com/q/37365866). No such option exists in the SDKS, and as Dhararaj commented, the common workaround is to have a separate top-level node where you have only the keys (typically with a marker value of `true`, since keys must have a value to exist). If you want to get all data, but only print the keys, see: https://stackoverflow.com/a/46345639 and https://stackoverflow.com/a/50849420 – Frank van Puffelen Aug 22 '21 at 19:46
  • You just cannot fetch the keys only. The best option would be to use the REST API Shallow queries https://firebase.google.com/docs/reference/rest/database#section-param-shallow run a query on splits node but it'll return an object with split IDs like this: `{splits: {split1: true, split2: true}}` – Dharmaraj Aug 22 '21 at 19:46

0 Answers0