Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda