2 回答
TA贡献1820条经验 获得超2个赞
db.collection.aggregate([
{
"$match": {
"name": "Mulandi"
}
},
{
"$unwind": "$Section"
},
{
"$unwind": "$Section.Content"
},
{
"$match": {
"Section.Content.ID": "61f5586e3fd9b086c3a422dc"
}
},
{
"$project": {
"Subsection_Title": "$Section.Content.Subsection_Title",
"Content": "$Section.Content.Content",
"_id": "$Section.Content.ID"
}
}
])
mongoplayground
TA贡献1883条经验 获得超3个赞
iuud, _ := primitive.ObjectIDFromHex(subsectionid)
pipeline := []bson.M{
{"$match": bson.M{"Name": name}},
{"$unwind": "$Section"},
{"$unwind": "$Section.Content"},
{"$match": bson.M{"Section.Content.ID": iuud}},
{"$project": bson.M{
"Subsection_Title": "$Section.Content.Subsection_Title",
"Content": "$Section.Content.Content",
"_id": "$Section.Content.ID",
}},
}
iter, err := collection.Aggregate(ctx, pipeline)
if err != nil {
return nil, err
}
var results []bson.M
if err = iter.All(context.TODO(), &results); err != nil {
log.Fatal(err)
}
- 2 回答
- 0 关注
- 92 浏览
添加回答
举报