【发布时间】:2020-03-04 18:32:06
【问题描述】:
我有多个文档,每个文档都有一组推文。 我可以按名称找到文档,如下所示:
client = MongoClient('localhost', 27017)
db = client['sample_app']
s = db['s']
s.find(
{
"name": "temp16"
}
)
当我运行上述查询时,我得到以下数据:
{"_id": {"$oid": "5e57db66c6bb04eb902589a2"}, "name": "temp16", "tweets": [{"tweet_id": "1234762637361086465", "tweet_text": "Had an extensive review regarding preparedness on the COVID-19 Novel Coronavirus. Different ministries & states are working together, from screening people arriving in India to providing prompt medical attention.", "tweet_handle": "@narendramodi", "labels": ["A", "B", "C", "D", "E"]}, {"tweet_text": "There is no need to panic. We need to work together, take small yet important measures to ensure self-protection.", "tweet_id": "1234762662413660165", "tweet_handle": "@narendramodi", "labels": ["A", "B", "C", "D", "E", "F"]}]}
我的目的是仅在本文档中获取 ID 为 "1234762662413660165" 的推文。所以我尝试以下方法:
s.find(
{
"name": "temp16",
'tweets': {"tweet_id": "1234762662413660165"}
},
)
但是我得到None
我做错了什么?
【问题讨论】: