【发布时间】:2019-01-03 06:23:25
【问题描述】:
我正在查找 mongoose 中的两个集合:
我的第一个收藏:[文件夹]
{
"_id" : ObjectId("00000000c27b9d0d045ff376"),
"folder_name" : "Testing 2",
"status" : "Y",
"parent_id" : [
ObjectId("00000000666e6e2084393a11")
],
"created_date" : ISODate("2018-07-24T15:10:38.456+05:30"),
"updated_date" : ISODate("2018-07-24T15:10:38.456+05:30")
}
我的第二个收藏:[检查]
{
"_id" : ObjectId("5b55bb043f37a8f292e1ada2"),
"project_id" : ObjectId("00000000666e6e2084393a11"),
"inspection_data" : [
{
"_id" : ObjectId("5b3b3aa86b20153284d45a54"),
},
{
"_id" : ObjectId("5b3b3aa86b20153284d45a54"),
}
]
}
我的查询查询
mongo.folder.aggregate([
{
$lookup:
{
from: 'inspections',
localField: '_id',
foreignField: 'project_id',
as: 'projectdata'
}
},
{ $match : {
$and: [
{'parent_id': ObjectId(req.body.folder_id)},
]
}
},
{
"$project": {
"_id" : 0
"inspection_count" {$size:"$projectdata.inspection_data"}
}
}
]).exec(function (err, response) {
console.log(response) // It should show inspection count as 2 but its showing 1
})
如果我正在为项目数据放松,意味着我只获取一个数据。还有其他方法吗
【问题讨论】:
-
你能展示预期结果的样本吗?
-
检查次数应为 2
标签: javascript arrays mongodb mongoose aggregation-framework