【发布时间】:2018-02-03 16:00:48
【问题描述】:
我有一个嵌套的 mongodb 数据库,我正在尝试执行一个查找条目并仅返回某些字段的查询。
我要返回的字段是嵌套的
数据库是这样的
{
'material_type':'solid',
'performance':10,
'material': {'isotopes': [ { 'abundance': 0.9,
'atomic_number': 6,
},
{ 'abundance': 0.1,
'atomic_number': 7,
}
]
},
},
{
'material_type':'solid',
'performance':9,
'material': {'isotopes': [ { 'abundance': 0.7,
'atomic_number': 6,
},
{ 'abundance': 0.3,
'atomic_number': 7,
}
]
}
}
我想返回嵌套的丰度字段,但仅如果原子序数等于 6。
我尝试对查询执行投影,目前在 python pymongo 中有类似的东西
results = database.find({'material_type':'solid'},
{'performance':True,
'material.isotopes':True
})
我认为我需要一个投影操作,但无法让它们在 pymongo 中工作。 任何想法 pymongo database.find 操作应该是什么来返回以下字段和值?
performance , abundance
10 0.9
9 0.7
【问题讨论】:
标签: python mongodb operators pymongo projection