Golang BSON转换 [英] Golang BSON conversion

查看:196
本文介绍了Golang BSON转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在golang中将有效的mongo查询转换为bson.我掌握了一些基本知识,但仍在努力寻找如何将更高级的or查询集成到组合中的方法.

I am trying to convert a working mongo query to bson in golang. I have the basic stuff down and working but am struggling to figure out how to integrate more advanced or queries into the mix.

有人有时间帮助我转换以下查询吗?希望它应该给我我需要的方向...不幸的是,除了评估和查询之外,我无法找到许多示例.

Anyone have a minute to help me convert the following query? It should hopefully give me the direction I need... Unfortunately I have not been able to find many examples outside of just evaluating and queries.

这在mongo中有效:

This works in mongo:

db.my_collection.find({"$or": [
      {"dependencies.provider_id": "abc"}, 
      {"actions.provider_id": "abc"}]})

这在golang/bson中有效:

This works in golang/bson:

bson.M{"dependencies.provider_id": "abc"}

如何正确引入or语句?

推荐答案

在您的情况下,它将是:

In your case, it would be:

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

这篇关于Golang BSON转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆