I believe you can simply use
{
"rules": {
"chats": {
"$chatid": {
"participants": {
".indexOn": ".value"
}
}
}
}enter code here
}
in database rules and then in your code use
ref.child("chats").orderByChild("participants/john").equalTo(true)