Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

326
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!