MongoDB 多表查询
mongoDB 多表联查
·
db.book.aggregate([
{
$match:{
sign_status: "xfinish"
}
},{
$lookup: {
from: "user",
localField: "user_id",
foreignField: "_id",
as: "user"
}
},
{
$lookup: {
from: "chapter",
localField: "_id",
foreignField: "book_id",
as: "chapter"
}
}
,
{
$unwind:{
path:"$chapter",
preserveNullAndEmptyArrays: true,
}
},
{
$group:{
_id:{id:"$_id",name:"$name",chpater_book:"$chapter.book_id",penname:"$user.penname",username:"$user.name",signType:"$sign_type",attribute:"$attribute",finish_time:"$finish_time",wordCont:"$word_count"},
count2:{$sum:1}
}
}
]
)
更多推荐
已为社区贡献1条内容
所有评论(0)