Golang BSON conversion

核能气质少年 提交于 2019-12-04 11:50:49

In your case, it would be:

bson.M{"$or": []bson.M{
    {"dependencies.provider_id": "abc"},
    {"actions.provider_id": "abc"},
}}

For completeness here is a full example of my last question in the comments above. The larger goal was dynamically building a bson query in go. Huge thanks to ANisus:

query := bson.M{}
query["origin"] = "test"
query["$or"] = []bson.M{}
query["$or"] = append(query["$or"].([]bson.M), bson.M{"abc": "1"})
query["$or"] = append(query["$or"].([]bson.M), bson.M{"def": "2"})

like this

package main
import "github.com/globalsign/mgo/bson"

query := make([]map[string]interface{}, 0)
query = append(query, map[string]interface{}{"dependencies.provider_id": "abc"})
query = append(query, map[string]interface{}{"actions.provider_id": "abc"})
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!