我有这个文档,想过滤它以获取并记录在 Content 数组中:
[
{
"ID": "61f1244daeaea5f165851fc9",
"name": "Mulandi",
"author": "Owayo",
"description": "dnjsfnvlksfnvls",
"created_at": "2022-01-26T10:37:01.558Z",
"Section": [
{
"ID": "61f557213fd9b086c3a422c5",
"Title": "Weee",
"Content": [
{
"ID": "61f5586e3fd9b086c3a422dc",
"Subsection_Title": "Idk",
"Content": "Something"
}
]
}
],
}
]
我应该怎么做才能过滤这个文件我试过这个但它没有用:
pipeline := []bson.M{
{"$match": bson.M{"Name": name}},
{"$unwind": "$Section"},
{"$unwind": "$Section.Content"},
{"$project": bson.M{
"Section.Title": sectiontitle,
"Section.Content.subsectionid": iuud,
}},
}
iter, err := collection.Aggregate(ctx, pipeline)
if err != nil {
return nil, err
}
var elem models.Course
for iter.Next(ctx) {
var elem models.Section
err = iter.Decode(&elem)
if err != nil {
log.Fatal(err)
}
}
DIEA
白板的微信
相关分类