Firebase function how to search realtime database

Viewed 160

enter image description here

I want to search firebase realtime database using firebase functions Ex: in users I want to search if a particular email already exists.

1 Answers

You can use orderByChild() and equalTo() methods.

async function doesEmailExist(email) {
  const snap = await admin.database().ref("users").orderByChild("email").equalTo(email).once("value")
  return !!snap.val()
  // snap.val() is null if absent
  // function returns false is email is absent
}
Related