我想从对象数组中查找文档,但它不返回所有索引。
[
{
"uuid": "feed-001",
"comments": [
{ createBy: 'user-001', text: 'Hello' },
{ createBy: 'user-001', text: 'Who there ?' },
{ createBy: 'user-002', text: 'Hi' },
],
},
]
[
{
"uuid": "user-001",
"name": "Jack",
},
{
"uuid": "user-002",
"name": "Max",
},
]
FeedModel.aggregate([
{
$lookup: {
from: 'users',
localField: 'comments.createBy',
foreignField: 'uuid',
as: 'userInfo',
},
}
])
userInfo
不包含 3 个对象,IDK 为什么
[
{
"uuid": "feed-001",
"comments": [
{ createBy: 'user-001', text: 'Hello' },
{ createBy: 'user-001', text: 'Who there ?' },
{ createBy: 'user-002', text: 'Hi' },
],
"userInfo": [
{
"uuid": "user-001",
"name": "Jack",
},
{
"uuid": "user-002",
"name": "Max",
},
],
}
]
我需要为每个评论获取 userInfo
谢谢