我想获取python3 pymongo由“名称”建立的“数据”项目中的每个“ ecg_raw”。
如果我知道'name'和'time_info',我如何获取4个ecg_raw数据,其中time_info =='2018-09-01 00:00:03'
我想获取每个[[8,2],[1,10],[9,4],[1,9]]之类的ecg_raw数据
我尝试了
db.g.find({"data":{"$elemMatch":{"time_info":"2018-09-01 00:00:03"}}},{"name":1,"data":{"$elemMatch":{"time_info":"2018-09-01 00:00:03"}}})
但它只返回一个值,如bottom。
{'_id': ObjectId('5b90d401219e9c9f72cac8c4'), 'name': 'testDog3', 'data': [{'time_info': '2018-09-01 00:00:03', 'ecg_raw': [8, 2]}]}
请帮助我。
> db.g.find().pretty()
{
"_id" : ObjectId("5b90d401219e9c9f72cac8c4"),
"name" : "testDog3",
"data" : [
{
"time_info" : "2018-09-01 00:00:03",
"ecg_raw" : [
8,
2
]
},
{
"time_info" : "2018-09-01 00:00:03",
"ecg_raw" : [
1,
10
]
},
{
"time_info" : "2018-09-01 00:00:03",
"ecg_raw" : [
9,
4
]
},
{
"time_info" : "2018-09-01 00:00:03",
"ecg_raw" : [
1,
9
]
},
{
"time_info" : "2018-09-01 00:00:04",
"ecg_raw" : [
10,
6
]
},
{
"time_info" : "2018-09-01 00:00:04",
"ecg_raw" : [
1,
6
]
}
]
}
答案 0 :(得分:3)
尝试一下。
aggregate([{$ match:{'name':'testDog3'}},{“ $ unwind”:“ $ data”},{“ $ match”:{“ data.time_info”:“ 2018-09 -01 00:00:03“}}])