I am building a simple group chat application in Java, I have created the follwing structure in Firebase realtime database:
"GROUPS":{
  "-LuSuWF4JjYNyjJ2Y5c4" : {
    "GROUP_MEMBERS" : {
      "qyM8p4IgJ7cFOBDNWeFjlaMjNsk2" : {
        "dateAdded" : "23/11/2019",
        "permissions" : 0,
        "user" : "email@email.com"
      }
    },
    "dateCreated" : "23/11/2019",
    "description" : "A dummy test group",
    "name" : "Group 2"
  }
I need to get all of the Groups given a user's UID, I am trying to run the following query from java but it is not working.
    public static Query getGroupsByUser(String uid){
       return FirebaseDatabase.getInstance().getReference(GROUPS).orderByChild(GROUP_MEMBERS).orderByKey().equalTo(uid);
    }
how should I make this query? or Is there a better way to structure my database schema?
Please Help!
 
     
    