【发布时间】:2021-05-02 20:26:33
【问题描述】:
我对 MongoDB 很陌生,我正在尝试查询我导入的一些数据。我昨天和今天试了几个小时,我的理解有了进步,但仍然没有任何结果。我尝试从博客、stackoverflow、youtube 甚至 MongoDB 网站一步一步地跟踪事情,但仍然无法正确地将其转换为我的数据。我希望有人能指出我正确的方向,而不是找人为我编写代码。这是我正在做的菜:
数据片段:
{'_id': ObjectId('608dd1a2abf9c97d8d771c41'),
'competition': {'area': {'id': 2072, 'name': 'England'},
'code': 'PL',
'id': 2021,
'lastUpdated': '2021-04-17T02:20:14Z',
'name': 'Premier League',
'plan': 'TIER_ONE'},
'filters': {},
'season': {'currentMatchday': 34,
'endDate': '2021-05-23',
'id': 619,
'startDate': '2020-09-12',
'winner': None},
'standings': [{'group': None,
'stage': 'REGULAR_SEASON',
'table': [{'draw': 5,
'form': 'W,W,L,W,W',
'goalDifference': 47,
'goalsAgainst': 24,
'goalsFor': 71,
'lost': 4,
'playedGames': 34,
'points': 80,
'position': 1,
'team': {'crestUrl': 'https://crests.football-data.org/65.svg',
'id': 65,
'name': 'Manchester City FC'},
'won': 25}}
我想要达到的目标: 我试图查询standings.table.team.name 但没有成功。我退后一步,开始专注于查询competition.name。
我尝试过的: 我使用以下查询尝试使用 Python 的一些(不是全部)事情:
db.standings.find_one( {'standings.table.team.name': "Manchester City FC"})
db.standings.find_one( {'standings.table.team.name': 'Manchester City FC'})
db.standings.find_one( {'competition.name': "Premier League"})
db.standings.find_one( {"competition.name": 'Premier League'})
db.standings.find_one( {'competition.name': 'Premier League'})
db.standings.find_one( {"competition.name": "Premier League"})
-- 我这里的所有结果都返回数据库中的所有数据。
在 MongoDB Compass UI 中进行的尝试:
-
手动输入过滤器:{'competition.name': 'Premier League'}
-
手动输入过滤器:{"competition.name": 'Premier League'}
-
手动输入过滤器:{'competition.name': "Premier League"}
-
手动输入过滤器:{'standings.table.team.name': 'Manchester City FC'}
-
手动输入过滤器:{'standings.table.team.name': "Manchester City FC"}
-
我转到 Schema 并导航,为英超联赛和曼城足球俱乐部添加过滤器。然后回到文件,仍然没有运气。我要么什么都没有返回,要么数据库中的所有数据都没有。我不能只得到这个字段。
我也在 Mongo Shell 中尝试过,但我上面使用的语法几乎是我在 shell 中不断重复的,但仍然没有运气。
对于我在这里缺少的内容,我可以获得任何帮助或指示吗?我确实尝试过研究并尝试不同的变化和组合,但仍然没有得到任何结果。
【问题讨论】:
标签: mongodb mongodb-query pymongo-3.x