第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用官方 mongo 驅(qū)動(dòng)程序查找嵌套文檔 mongodb

如何使用官方 mongo 驅(qū)動(dòng)程序查找嵌套文檔 mongodb

Go
Helenr 2022-10-31 16:55:53
我有這個(gè)文檔,想過濾它以獲取并記錄在 Content 數(shù)組中:[{    "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"                }            ]        }    ],}]我應(yīng)該怎么做才能過濾這個(gè)文件我試過這個(gè)但它沒有用: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)        }    }
查看完整描述

2 回答

?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超3個(gè)贊

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


查看完整回答
反對(duì) 回復(fù) 2022-10-31
?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊

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)

}


查看完整回答
反對(duì) 回復(fù) 2022-10-31
  • 2 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)