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

242
Visualizações
Using equalTo() function in Firebase Database JavaScript v9

I am trying to use the equalTo function in the Firebase Database JavaScript v9 SDK. It's not very well documented like V8 is so can't figure out how to do what I want to do.

I want to filter results by the type field. My parent field is request-log with child elements like below.

{"backtrace":false,"message":false,"organisationID":"Empty","postData":false,"referrer":"Empty","remoteIP":"0.0.0.0","requestMethod":"POST","time":1630129562,"type":"Error","url":"Empty","user":{"email":"Empty","firstName":"George","id":37,"lastName":"Bates"},"userAgent":"Empty"}

I am trying the following, but not getting any results when loaded:

const readNewLogEntries = query(child(ref(db), 'request-log'), equalTo('Error', 'type'));

I have also tried this, as the reference docs say for the 2nd argument in the equalTo() function

This argument is only allowed if ordering by child, value, or priority.

But this isn't working either

const readNewLogEntries = query(child(ref(db), 'request-log'), orderByChild('type'), equalTo('Request', 'type'));

EDIT: Screenshot of DB

Screenshot of DB

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

0

Remove the second parameter from equalTo().

The optional key argument can be used to further limit the range of the query. If it is specified, then children that have exactly the specified value must also have exactly the specified key as their key name. This can be used to filter result sets with many matches for the same value.

const getData = async () => {
  const readNewLogEntries = await get(
    query(ref(db, "request-log"), orderByChild("type"), equalTo("Request"))
    // Filters where "type" is equal to "Request". Single arg here ⬆ 
  );
  console.log(readNewLogEntries.val())
  return readNewLogEntries.val();
};

You can read more about the parameters in the documentation

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