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

195
Views
Check if value exist firebase

I'm trying to check if there is a cart with a userID but it doesn't seem to be working enter image description here

Here is my code attempt, I don't know where I'm going wrong, I have firebase initialized

let storage = Cart.shared.firebase
    storage.child("cart").orderByChild("userId").equalTo("Eyo1DCNZU8TfB16zJDuULpKAx2V2").once("value",snapshot => {
                    if (snapshot.exists()){
                      const userData = snapshot.val();
                      console.log("exists!", userData);
                    }else{
                        console.log("nope")
                    }
                });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using Firestore but writing code for Realtime database. Try the code below:

firebase.firestore().collection("cart").where("userId", "==", USER_ID).get().then((qSnap) => {
  if (qSnap.empty) {
    console.log("No cart found for user")
  } else {
    console.log("User carts")
    qSnap.docs.forEach((d) => {
      console.log(d.data())
    })
  }
}) 
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!