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

268
Visualizações
"query is not a function" Next Js getServerSideprops and firebase error

I'm using NextJS and firebase as my primary database for the app that I'm currently building for an NGO. and I ran into an issue.

import {
  collection,
  where,
  query,
  getDocs
} from '@firebase/firestore';
import { db } from '../../../services/firebase';

export async function getServerSideProps({query}) {
  
  const user = await getDocs(query(collection(db, 'members'), where('id', '==', query)))
  return {
    props: {
      // VisionInfo: JSON.stringify(user.docs.map(item => item.data()))
      json: JSON.stringify('Hello')
    }
  };
}

The only way to get Query from the URL in NextJS in serverSideProps is to use the keyword "query" but the same keyword is used to fetch firebase document. The error shows "query is not a function" Is there anyway I could get Query into serversideprops ?

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

0

The issue arises because you also have "query" in getServerSideProps parameters. Try naming the import from Firestore SDK (or the query param) as shown below:

import { query as fireQuery } from '@firebase/firestore';

export async function getServerSideProps({query}) {
  const user = await getDocs(fireQuery(collection(db, 'members'), where('id', '==', query)))
  // use fireQuery here      ^^^
})
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