我正在尝试获取给定用户拥有的所有股票的数组。
...
const user = await User.findById(verified._id);
if (!user) {
return next(new ErrorLibrary('No user found', 401));
}这是我用来检索用户id的代码。下一步(我一直在做的)是获取与用户相对应的所有股票的数组。
我已经尝试过了
const stock = await User.stocks.findById(req.params.id);
if (!stock) {
return next(new ErrorLibrary('No stock found', 401));
}
OUTPUT:
"Cannot read properties of undefined (reading 'findById')"[
{
"_id":"61534b363e5f39d6ce2c2c57",
"firstName":"firstname",
"lastName":"lastname",
"email":"email",
"password":"$2a$10.......",
"tokenVersion":0,
"stocks":[
{
"ticker":"TEST",
"lots":[
{
"per_share_cost":1220,
"quantity":2,
"_id":"6153608867fae1373d272a4a",
}
],
"_id":"6153608867fae1373d272a49"
}
],
"__v":0
}
]发布于 2021-09-28 21:37:14
简单地试一下
await User.find({applyYourConditionHere});https://stackoverflow.com/questions/69368680
复制相似问题