mongodb - 如何在 mongdb 中获取值
问题描述
这是我在 Mongodb 中的数据
{
"d" : {
"results" : [
{
"slack_id" : "RAGHU@TN.COM",
"connector_id" : "GRECLNT900",
"sys_role" : "DEV",
"user_id" : "RAGHU"
},
{
"slack_id" : "RAGHU@TN.COM",
"connector_id" : "GRECLNT900",
"sys_role" : "PRD",
"user_id" : "RAGHU",
"question" : "What is your favorite color?",
"Answer" : "Orange"
},
]
}
}
如果我给 RAGHU@TN.COM。然后我想显示 sys_role。像这样输出[DEV, PRD]
我正在尝试这种方式
x = mydb.mycollection.distinct("sys-role")
但我得到一个空数组[ ]
解决方案
您必须将光标视为引用(我个人将其视为 C 中的引用),然后将其取消引用以查看结果。(地址内部是什么)对于特定列,这是命令的结果迅速的:
my_cursor = mydb.mycollection.distinct("sys-role")
for x in my_cursor:
print('{0}'.format(x['sys_role']))
推荐阅读
- sql - 查询以查找空闲时间,即 GPS 经纬度在 15 分钟内显示相同的坐标
- java - 每个基于 Oracle 的代码都与 OpenJDK 一起使用吗?
- reactjs - 从反应类组件导入状态值
- abap - 如何将多个参数传递给子程序?
- vb.net - 有没有办法从引用类型中获取值?
- android - 在 google play console APK 详细信息中,原生平台的“差异化”和“通用”是什么意思?
- ios - 使用特定号码打开 Google Voice 应用
- java - DJI SDK:改变输入视频流的分辨率。还有破帧
- angular - Angular:在 index.html 中用于生成的网络工作者
- php - 为什么php密码验证失败?