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

277
Visualizações
Firestore query (Web v9) not returning any results

I'm trying to query a very simple collection that looks like this:

urls: {
    07WmGw7w0N8JiD7j1P60: {
       url: "www.yay.com"
    },
    07WmGw7w0N8JiD7j1P60: {
       url: "www.anotherurl.com"
    }
}

So my code looks like this:

export async function checkDoc() {
  try {
    const urlsRef = await collection(db, "urls");
    const q = await query(urlsRef, where("url", "==", "www.yay.com"));

    console.log(q)
    return q
  } catch (e) {
    console.error("Error querying document: ", e);
    return e.response
  }
}

But the response I'm getting is like this:

enter image description here

As far as I can tell, this is exactly how this is done in the documentation. I already trawled similar answers on Stackoverflow, but they mostly use the Web v8 chaining method which I'm not sure how to implement with my current setup. Is the issue with the way I'm using firebase or with the way I'm making the asynchronous call?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is because you actually don't query the database but you just build a query (i.e. the q object).

To query/fetch the database according to this query you need to pass this query to the getDocs() method, as follows:

export async function checkDoc() {
  try {
    const urlsRef = collection(db, "urls");
    const q = query(urlsRef, where("url", "==", "www.yay.com"));

    const querySnapshot = await getDocs(q);

    querySnapshot.forEach(docSnap => {
        // ....
    })

    return ...   // Generate the returned object in the forEach loop, see link below

  } catch (e) {
    console.error("Error querying document: ", e);
    return e.response
  }
}

This is shown here in the Firestore documentation. Note that the collection() and query() methods are not asynchronous, hence there is no need to call them with await. On the opposite, getDocs() is asynchronous.

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