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 關注
- 112 瀏覽
添加回答
舉報