这些是数据库中的blog对象:
[
{
_id: 5fec92292bbb2c32acc0093c,
title: 'Boxing ring',
author: 'T. Wally',
content: 'boxing stuff',
likes: 0,
user: {
_id: 5fd90181d1e88a13109433f9,
username: 'Johnny_23',
name: 'John Q'
},
__v: 0
},
{
_id: 5fec9481ce9c4a47a0ca6a2a,
title: 'Football OP',
author: 'RQ',
content: 'it`s football',
likes: 2,
user: {
_id: 5fec942dce9c4a47a0ca6a29,
username: 'malcomm',
name: 'Malcom'
},
__v: 0
}
]
我只想找到并显示属于某个用户的博客
listRouter.get('/', async (request, response) => {
const blogs = await Blog
.find({}).populate('user', { username: 1, name: 1 })
response.json(blogs)
})
我如何访问每个对象的用户id,并以一种我可以匹配博客的方式使用它?
由于属性
会有一种情况,字段