Reputation: 3320
I have the following structure in Realtime Database:
I've read a few questions on SO that it's possible and some say it's not possible so I'm a little confused on if this can be done or not but here goes.
I have multiple members (about 200) and I would like to return only those that are mStatus == true.
I attempted it by doing this:
const dbRef = ref(db, `organization/${org}/members`);
const queryConstraints = [orderByChild("mStatus"), equalTo("value")]
get(query(dbRef, ...queryConstraints)).then((snapshot) => {
if(snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log('No data available');
}
})
The return is null here is the security rule I use:
"rules": {
".read": true,
".write": true,
"members": {
".indexOn": ["mStatus"]
}
}
How would I run this query?
Upvotes: 0
Views: 36
Reputation: 599726
Since in the comments you said that your members
list is under /organization/{uid}/
, that is also where you have to define the index in your rules:
{
"rules": {
...
"organization": {
"$uid": {
"members": {
".indexOn": ["mStatus"]
}
}
}
}
}
Upvotes: 1