这是我的mongodb“个人资料”
{
"_id":{"$oid":"5eabd07815cb2679af47701a"},
"user":{"$oid":"5ea54ee9ee3a62a79df1501f"},
"bio":"blah blah",
"date":{"$date":"2020-05-01T07:32:08.583Z"},
"__v":22,
"trainings":
[{
"_id":{"$oid":"5ead9489ab3cd28a0acfadab"},
"training":{"$oid":"5eabcd64c1499375c502b7fe"},
"status":0}
]}
我可以用以下代码填充“用户”:
const profile = await Profile.findOne({
user: req.user.id,
})
.populate("user")
我从个人资料const中获得了这个信息
"_id": "5eabd07815cb2679af47701a",
"user": {
"_id": "5ea54ee9ee3a62a79df1501f",
"username": "blah",
"email": "blah@gmail.com",
"avatar": "blah blah",
"password": "asdasda233123k1j2312l3kOArzuW7iWttO1/n0JDOctybGzdfetNZm",
"date": "2020-04-26T09:05:45.897Z",
"__v": 0
},
"bio": "blah blah",
"date": "2020-05-01T07:32:08.583Z",
"__v": 22,
"trainings": [
{
"_id": "5ead9489ab3cd28a0acfadab",
"training": "5eabcd64c1499375c502b7fe",
"status": 0
}
]
问题是,如何在培训中填充“培训”?就像用户
答案 0 :(得分:0)
好吧,我已经这样做了:
const profile = await Profile.findOne({
user: req.user.id,
})
.populate("user")
.populate("trainings.training");