Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda