如何在集合中执行筛选。例如,我收集了这样的数据,我想做这个rits_dbx_1>0.2,simon_dbx_1<0.5
{
"threads":{
"threads_participants":{
"participant":[
{
"@all_user_n_grams":"0",
"@reference":"rits_dbx_2",
"overall_user_participation":"0.0",
"thread":{
"@thread_id":"5e778ea6a28f9a3881c330b4",
"#text":"{'relative_to_thread_interactors': 0.0, 'relative_to_self_threads': 0}"
}
},
{
"@all_user_n_grams":"11",
"@reference":"rits_dbx_1",
"overall_user_participation":"1.0",
"thread":{
"@thread_id":"5e778ea6a28f9a3881c330b4",
"#text":"{'relative_to_thread_interactors': 1.0, 'relative_to_self_threads': 1.0}"
}
}
]
}
}
}首先,我尝试使用find方法获得值。
db.xml_collection.find({"threads.threads_participants.participant": {"@reference": "rits_dbx_2"}})它也什么也没回。你能帮上忙吗?
发布于 2020-04-09 18:06:44
我知道你你想要找到
"@reference":"rits_dbx_2“和"overall_user_participation":"$gt":0.5
或
@reference:“simon_dbx_1”和"overall_user_participation":"$lt":0.2
如果是的话:
list(db.xml_collection.find({"$or": [{"threads.threads_participants.participant.@reference":"rits_dbx_2","threads.threads_participants.participant.overall_user_participation":{"$gt":"0.2"}},{"threads.threads_participants.participant.@reference":"simon_dbx_1","threads.threads_participants.participant.overall_user_participation":{"$lt":"0.2"}}]}))我还建议您在overall_user_participation字段中使用浮点数而不是字符串来提高比较性能和正确性。
https://stackoverflow.com/questions/61125192
复制相似问题