Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!