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

160
Views
finding a specific document using one of the fieds from firebase

I have an app (react-native) I am making a search query that finds a specific document based on one of the documents fields, it is a barcode that can be scanned, and then using the scanned value want to look for the object in the firebase, every object has the field that holds the value for the barcode. I just want to find it.

I followed this tutorial.

this is what I have currently:

  useEffect(() => {
    saveData();
  }, []);

const saveData = async () => {
    const productRef = db.collection("products");
    const queryRef = await productRef.where("barCode", "==", data).get();
    console.log(queryRef);
}

but this doesn't return the correct result, what am I missing?

this is the screenshot of console log but at the end I have this:

(truncated to the first 10000 characters)

enter image description here

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

0

const queryRef = await productRef.where("barCode", "==", data).get();

This query returns a QuerySnapshot which has a docs property that is an array of DocumentSnapshot. You can them map a new array containing the data from documents and set it in state:

const [products, setProducts] = useState([])

const saveData = async () => {
    const productRef = db.collection("products");
    const queryRef = await productRef.where("barCode", "==", data).get();
    setProducts(queryRef.doc.map(d => ({id: d.id, ...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!