I want to query my MongoDB database to only fetch all the values in my array using my user_id
I have tried using the (schema.name), it not working out
// @route GET api/user/package
// @desc Get all package
// @access Private
router.get('/package',
passport.authenticate('jwt', { session: false }),
(req, res) => {
Shipments.find({_id : req.user._id},{paymentStatus: "incomplete"})
.then(shipments => res.status(200).json(shipments.packages))
.catch(err =>res.status(404).json({ nopackages: 'No package found for you now' }));
});
Here is my expected result
"packages": [
{
"date": "2019-09-23T12:52:14.226Z",
"_id": "5d88bffe2a6ed7b8d9873548",
"category": "hazard",
"quantity": "10",
"description": "a valueablegoods",
"length": 10,
"height": 20,
"width": 12,
"weight": 12
},
{
"date": "2019-09-23T12:52:58.129Z",
"_id": "5d88c02a2a6ed7b8d9873549",
"category": "hazard",
"quantity": "10",
"description": "a valueablegoods",
"length": 10,
"height": 20,
"width": 12,
"weight": 12
}
],
but postman didn't return any value but brings a status 200, but returns nobody