The World’s Largest Online Community for Developers
I am wanting to fetch all users that contain a child node 'notificationToken' and exclude all users that don't have this node. I am using the following:
const ref = admin.database().ref('/Users'); const users = await ref.orderByChild('notificationToken').equalTo(****WHAT GOES HERE****).once('value').then((snapshot) => snapshot.val());
I'm not sure if equalTo can do what I want, I know I can use it to match exact strings or booleans, but how can I use it to match if the user has the notificationToken node?
You can use
equalTo to match the exact value of a node/property in the database.
Returns child nodes of
ref for which the
notificationToken property has the exact same value as
value. From that last link it follows that you can use
startAt(null) to get all child nodes that have the property, no matter what its value or type.
value can be any allowed JSON type, and must match the type that is stored in the database. So if
notificationToken is a string value,
value should be a string too.