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

117
Views
query from firebase realtime database

I am trying to get filtered data from my realtime database. In this example I want to get only these once with a specific uid:

enter image description here

I tried to get the data with the snippet from the firebase docs:

const db = getDatabase();
const auth = getAuth();
    
const myUserId = auth.currentUser.uid;
const myOffersRef = query(ref(db, 'allOffers/'), orderByChild('uid'), startAt(user.uid));

But how do I get the data from the const myOffersRef?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As shown in the documentation on reading data, you can use get to get the data at a path or for a query.

const myOffersRef = query(ref(db, 'allOffers/'), orderByChild('uid'), equalTo(user.uid));

get(myOffersRef).then((snapshot) => {
  snapshot.forEach((child) => {
    console.log(child.key, child.val().uid);
  });
}).catch((error) => {
  console.error(error);
});

Note that I also changed startAt to equalTo, as you likely only want the nodes that match the UID, not the slide of nodes starting from the first match (which is what startAt does).

The forEach is needed since a query can potentially have multiple results, so the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result.

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!