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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果 slice 存在并且它包含至少一個設(shè)置為 true 的特定變量

如果 slice 存在并且它包含至少一個設(shè)置為 true 的特定變量

Go
aluckdog 2022-07-11 16:23:02
我正在嘗試檢查訂閱部分是否存在,以及它是否包含至少一個名為 premium 的變量,其值為 true。如果是,它應(yīng)該返回,如果不是,它不應(yīng)該返回。目前它正在返回集合中的對象,即使該值設(shè)置為 false。// query to find all the users accounts that have purchased premium subscriptionshasPurchasedSubscriptions := c.QueryParam("hasPurchasedSubscriptions")if hasPurchasedSubscriptions != "" {    pipeline = append(pipeline, bson.M{        "$match": bson.M{"$and": []interface{}{            bson.M{"subscriptions": bson.M{"$exists": true}},            bson.M{"subscriptions": bson.M{"$elemMatch": bson.M{"premium": true}}},        }},    })}})
查看完整描述

1 回答

?
慕村225694

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個贊

只需使用:


pipeline = append(pipeline, bson.M{

    "$match": bson.M{

        "subscriptions": bson.M{"$elemMatch": bson.M{"premium": true}},

    },

})

不需要檢查它是否存在,它必須,否則它不能有一個帶有premium=true.


如果您對元素只有這一個條件,您還可以將其簡化為:


pipeline = append(pipeline, bson.M{

    "$match": bson.M{"subscriptions.premium": true},

})


查看完整回答
反對 回復(fù) 2022-07-11
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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