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

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

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 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!