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

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

如何在 Golang 的 mgo 查詢中運(yùn)行 $and 運(yùn)算符

如何在 Golang 的 mgo 查詢中運(yùn)行 $and 運(yùn)算符

Go
BIG陽 2022-01-10 14:33:38
我想在 Golang 的 MongoDB 中執(zhí)行以下查詢check_select = bson.M{            "$and": []interface{}{                "shr_key": user_shr_key,                "id": uid,                "user_history": bson.M{"$elemMatch": bson.M{"action": "STOP", "message_id": mid}},            },        }請幫助...我收到以下錯(cuò)誤"index must be non-negative integer constant"。
查看完整描述

2 回答

?
慕尼黑的夜晚無繁華

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

錯(cuò)誤來自您初始化arrayin的方式go:


....

"$and": []interface{}{

    "shr_key": user_shr_key,

....

go數(shù)組不接受string作為索引。


無論如何,為了解決您的問題,從數(shù)組初始化中刪除索引并將鍵值對包裝進(jìn)去bson.M就可以了,例如:


bson.M{

            "$and": []bson.M{ // you can try this in []interface

                bson.M{"shr_key": user_shr_key},

                bson.M{"id": uid},

                bson.M{"user_history": bson.M{"$elemMatch": bson.M{"action": "STOP", "message_id": mid}}},

            },

        }


查看完整回答
反對 回復(fù) 2022-01-10
?
慕蓋茨4494581

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

在這里你可以看到,通過 $Match 獲取值,$and 使用 Golang MongoDB



pipeline := []bson.M{

bson.M{"$match": bson.M{"$and": []bson.M{bson.M{"storyID": storyID}, 

bson.M{"parentID": parentID}}}}

}


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

添加回答

舉報(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)