Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

327
Vistas
How to check if name already exists in Firebase Realtime Database (Firebase & JS)

I am trying to check if a name already exists on a Firebase Realtime Database that is structured as follows: enter image description here

Here is my code:

const players = Firebase.database().ref("players");

function nameCheck() {
        console.log(name);

        players
        .orderByChild('settlement_name')
        .equalTo(name)
        .once('value')
        .then(snapshot => {
            if(snapshot.exists()){
                let playerData = snapshot.val();
                console.log(playerData)
                setError('Settlement name already exists')
                return playerData
            } else {
                console.log('Settlement name not found');
            }
        })
    }

Can anyone tell me why this function is not correctly identifying when a name exists? I am logging the name at the start of the function and it matches those on the database, yet it will only return that the name is not found.

Thank you kindly. 🙂

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to use the nested child path, as explained in the doc.

    players
      .orderByChild('settlement/settlement_name')
      ...

PS: In case you check if a name exists in order to use this name to create a new database node (if it does not exist), you should use a Transaction.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda