Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

MongoDB Not Sending the API Back?

$
0
0

I have been trying to solve a query but there are some problems in it..

I have been using a database tool mongoDB and now am having troubles sending API via the selects fields limiting query..

Here's the code,

 // 4) Field Limiting
    if (req.query.fields) {
      const fields = req.query.fields.split(',').join('');
      query = query.select(fields);
    } else {
      query = query.select('-_v');
    }

    const tours = await query;

    //Response
    res.status(200).json({
      status: 'success',
      result: tours.length,
      data: {
        tours
      }
    });
  } catch (err) {
    res.status(404).json({
      status: 'failed',
      message: err
    });
  }
};

now it is supposed to send a result like this, enter image description here

but instead it is showing something like this, enter image description here

so its sending the API back,

someone please help..

I have been using VS Code as code editor and Postman software for testing APIs

Down is the Postman API request..

enter image description here


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>