2

Having some challenges querying my firebase database for an Android app I'm writing, I have the following structure;

Matches
 - Match_01
  - awayScore
  - awayTeam
  - date
  - gameID
  - homeScore
  - homeTeam
  - pitch
  - played
  - time
 - Match_02
  - awayScore
  - awayTeam
  - date
  - gameID
  - homeScore
  - homeTeam
  - pitch
  - played
  - time

I want to be able to query by using the gameID field, the problem I'm having is how to reference the gameID without explicitly setting a child("Match_01"), as I have Match_02, Match_03, etc... below is the code I'm playing with (which doesn't work, but gives you an idea of what I want to achieve). GetArgument is a value I'm passing into my fragment;

    DatabaseReference ref = database.child("Matches");
    Query gameQuery = ref.child().child("gameID").equalTo(getArgument);

Any help is appreciated.

1 Answer 1

2

Yes it can be done like this:

 DatabaseReference ref = database.child("Matches");
Query gameQuery = ref.orderByChild("gameID").equalTo(getArgument);

when you use orderByChild() you do not have to specify the direct child under Matches

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.