Reputation: 716
I have rethinkdb 'competition' table. At the second level I got runners and each runner have a list of results:
"total_results": {
"433915": [ #runner_id
{
"judge": "15561671",
"result": 5,
"round": "1"
},
{
"judge": "08136a59",
"result": 4,
"round": "1"
}
]
}
I do rethinkdb query:
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))
This piece of code works fine. Now I want to apply filter based on 'round' value. I add it right after the second .map() so results query looks like:
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))
But I'm getting empty list. And this is strange for me because if I move .filter() outside of rethinkdb query and do it like:
by_round = filter(lambda x: x['round'] == round, results)
I get results. There should be something I'm doing wrong in rethink query... Can you give me a tip please?
p.s. I have thousands results in the database. There should be dozens results based on my query params.
Upvotes: 1
Views: 256
Reputation: 5289
I think you want your second map
to be a concat_map
. (Alternatively, if you like the existing output format, you can put the filter
inside a map
like .map(lambda x: x.filter(...))
.)
Upvotes: 1