【发布时间】:2016-06-15 14:02:12
【问题描述】:
我已经重新思考数据库“竞赛”表。在第二级,我得到了跑步者,每个跑步者都有一个结果列表:
"total_results": {
"433915": [ #runner_id
{
"judge": "15561671",
"result": 5,
"round": "1"
},
{
"judge": "08136a59",
"result": 4,
"round": "1"
}
]
}
我重新思考数据库查询:
results = (r.table('competitions').filter(lambda c: c['unique_id'] == competition_id)
.map(lambda c: c['total_results'])
.map(lambda t: t[runner_id])
.run(conn))
这段代码运行良好。现在我想根据“round”值应用过滤器。我在第二个 .map() 之后添加它,因此结果查询如下所示:
results = (r.table('competitions').filter(lambda c: c['unique_id'] == competition_id)
.map(lambda c: c['total_results'])
.map(lambda t: t[runner_id])
.filter(lambda x: x['round'] == round)
.run(conn))
但我得到的是空列表。这对我来说很奇怪,因为如果我将 .filter() 移到 rethinkdb 查询之外并这样做:
by_round = filter(lambda x: x['round'] == round, results)
我得到了结果。 重新考虑查询时我应该做错了什么......你能给我一个提示吗?
附言我在数据库中有数千个结果。根据我的查询参数应该有几十个结果。
【问题讨论】: