I am very new to queries in Firebase and query-based rules. I am trying to use query-based rules to retrieve specific data from the database, if and only if the group_id
passed in the query is matching the group_id
in the database at the given user with {user_id}
Code
Database reference: ref(users/{user_id}
Query
db.ref()
.orderByChild("group_id")
.equalTo(group_id) <- variable
.on("value", (snapshot) => {
return snapshot.val();
});
JSON
root: {
"users" : {
"{user_id}" : {
"email" : "user@email.com",
"group_uid" : "{group_id}",
"name" : "username",
},
}
Rules
users:{
$user_id:{
".read": auth.uid != null
&& query.orderByChild == 'group_id'
&& query.equalTo == data.child('group_id').val()
}
}
My goal is to fetch the information about the user (email, group_uid and name), but the result returns null
, and I can't seem to understand why.