【发布时间】:2019-02-17 07:39:10
【问题描述】:
我有 mongo 集合,其中的文档如下所示:
{
_id: "384iojweiu83ur8233uui",
name: "Jack",
friends: [
{
_id: "384798237498234",
name: "Alfred"
},
{
_id: "384798234749829",
name: "Deborah"
}
]
}
我想检索一个给定_id 的人,并且只有一个给朋友_id 的朋友。像这样的:
{
_id: "384iojweiu83ur8233uui",
name: "Jack",
friend_id: "384798237498234",
friend_name: "Alfred"
}
我试图通过 c# mongo 驱动程序中的unwind 方法这样做,但是我被困在这一点上。
var people = await collection.Aggregate()
.Unwind<Person, PersonWithFriend>(_ => _.friends } )
.Match( _ => _.Id == new ObjectId("5b646004b5728100042dd358"))
.ToListAsync();
【问题讨论】:
标签: c# mongodb subquery aggregation