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

205
Visualizações
Code is not working as i want to fetch data based on filter

i sent a request to the mongodb to get some data according to email.my client side code is working properly . code is here:

useEffect(()=>{
    
    const email = user?.email;
    
    // console.log(email)
    
    const url = `http://localhost:5000/services?email=${email}`;
    
    console.log(url)
    
    fetch(url)
    
    .then(res => res.json())
    
    .then(data => setItems(data))
},[user])

console.log showing the data as i expected

but the problem start with the backend. i tried console.log to get the email and other thing but the code is not showing nothing even not a single error. here is the code i wrote for api with express:

app.get('/services',async(req,res)=>{
            
            const email = req.query.email;
            
            console.log(email)
            
            const query = {email:email};
            
            const cursor =  serviceCollection.find(query);
            
            const item = await cursor.toArray();
            
            res.send(item);
        });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So far I didn't see any issue with your code.

Have you tried to call your GET request from the browser directly?

You might check on req and res to see the incoming data to that endpoint (/services)

You also can try to add the request options in your fetch method

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

const email = user?.email;
    
const url = `http://localhost:5000/services?email=${email}`;

fetch(url , requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

And I suggest you to using Postman, to call that endpoint. It will easier to debug the API using 3rd party app like Postman.

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