Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda