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

270
Visualizações
Check for existence of value in firebase realtime database?

I'm using V9 (modular) version of Firebase realtime database. I have a list of URLs with auto-generated keys using push(). This is the data structure.

enter image description here

What I want is to check for the existence of one of these url's in the list. Here's what I've attempted.

    const testURL = "https://i.redd.it/bm6psl9sgsj81.png"; //First one in the list
    const db = getDatabase();
    const dbRef = ref(db, "burnedURLs/");
    const q = query(dbRef, equalTo(testURL));
    const snapshot = await get(q);
    const results = snapshot.toJSON();
    console.log(results); //Returns NULL

How does one check the existence of a value, or just retrieve a value when you don't know the key? The documentation for V9 isn't very good and most examples I've found are for V8. Thanks for any help.

Edit: Using exists() returns false when it does exist (It's the first child in the tree). I think the issue is that I'm not forming the query correctly and that's what I need help with.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The get(<query>) returns a DataSnapshot that still has exists() which returns true if this DataSnapshot contains any data.:

const q = query(dbRef, orderByValue(), equalTo(testURL));

const snapshot = await get(q);

if (snapshot.exists()) {
  const results = snapshot.val();
  console.log('Results', results)
} else {
  console.log('Data does not exist')
}

From the documentation,

To filter data, you can combine any of the limit or range methods with an order-by method when constructing a query.

So adding orderByValue() in query should solve the issue.

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