[
{
"userid": "abcde",
"dates": {
"2-01-2015": {
"9-10": {
"ava": "yes",
"bookibg_id": "null"
},
"10-11": {
"ava": "yes",
"bookibg_id": "null"
}
},
"3-01-2015": {
"9-10": {
"ava": "no",
"bookibg_id": "null"
},
"10-11": {
"ava": "no",
"bookibg_id": "null"
}
}
}
},
{
"userid": "abcde",
"dates": {
"2-01-2015": {
"9-10": {
"ava": "yes",
"bookibg_id": "null"
},
"10-11": {
"ava": "no",
"bookibg_id": "null"
}
},
"3-01-2015": {
"9-10": {
"ava": "no",
"bookibg_id": "null"
},
"10-11": {
"ava": "no",
"bookibg_id": "null"
}
}
}
}
]
对于nosql和mongodb.Its,我对如何查询这些问题还比较陌生。对于给定的db,如何编写查询以生成结果: Query:List userids,在"2-01-2015“中,"ava”在"9-10“处为"yes”。请解释一下结果。
发布于 2016-02-08 07:55:26
你可以找到使用
db.coll.find({'dates.2-01-2015.9-10.ava': "yes"},{"userid":1,'_id':0})
在这里,'dates.2-01-2015.9-10.ava':'yes'用于查找ava的值,它与从JSON对象访问值类似,而第二个参数仅用于从查询{" userid ":1,‘_id’:0}获得用户id
输出将是
{ "userid" : "abcde" }
{ "userid" : "abcde" }
如果删除第二个参数,将根据第二个参数在结果中获得整个文档,就可以过滤所需的feilds
https://stackoverflow.com/questions/35264369
复制相似问题