'I'm trying get data from server by id query but showing an empty array. there also console log not showing any error?

I'm trying get data from server by id query but it showing an empty array. There console log als not showing any error?

my server site code

    // get order for payment
    app.get('/myOrders/:id', async (req, res) => {
        const id = req.params.id;
        const query = { _id: id }
        console.log(query)
        const result = orderCollection.findOne(query);
        res.json(result)
    })

this is my code I write for get order from my orderCollection and when i try to test by locally, browser show an empty array. url that I try in my browser is http://localhost:5000/myOrders/618feeccf38ede94d3d96e17

Another problem is I try to the see the error in console but console also clear and no error showing.

my cmd terminal

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Time keeper new site, 5000
connected to time keeper


Solution 1:[1]

I'm answering my own question. There is a mistake to the server code the correct code will be

    // get order for payment
    app.get('/payment/:id', async (req, res) => {
        const id = req.params.id;
        const query = { _id: id }
        console.log(query)
        const result = await orderCollection.findOne(query);
        console.log(result)
        res.json(result)
    })
  1. firstly in the get you will use
app.get('/payment/:id', async (req, res) => {
            
        })
  1. secondly use await before the orderCollection();
const result = await orderCollection.findOne(query);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shakil Khan