我想查询我的 MongoDB 数据库,以便仅使用我的 user_id 获取数组中的所有值
我尝试过使用(schema.name),但没有成功
// @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' }));
});
这是我的预期结果
"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
}
],
但是 postman 没有返回任何值,但带来了状态 200,但没有返回任何人
最佳答案
尝试Shipments.findOne()
发生这种情况是因为您正在获取单个用户详细信息。
关于node.js - MongoDB 数组不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58064989/