2

My documents contain 7 fields, one of them is "city", values are different cities. When I do

r.db('base').table('table').group('city').count().run()

RethinkDB groups the number of documents by cities. The output is a list of 277 cities each one being associated with a number of documents. I'd like to have the same output, except that I'd only want to see cities associated with 96 or more documents.

For example, when the current query output is

{(u'Newtown Square',): 2, (u'Delhi',): 242, (u'Emeryville',): 19, (u'Chicago',): 96},

I'd like the new one to give

{(u'Delhi',): 242, (u'Chicago',): 96}

If possible, I'd also like the result to be ranked by descending order.

crocefisso
  • 557
  • 1
  • 5
  • 20

2 Answers2

2

Something like this would do it: r.db('base').table('table').group('city').count().ungroup().filter(function(row) { return row('reduction').ge(96); }).orderBy(r.desc('reduction')).

mlucy
  • 5,046
  • 1
  • 14
  • 20
  • Thx for your answer Lucy. Your query returns a syntax error, and I don't understand it well enough to be able to amend it. – crocefisso Apr 23 '16 at 22:00
  • Can't find `function` nor `return` in RethinkDB documentation. What is 'reduction' ? For the record, I'm using Python client driver. – crocefisso Apr 23 '16 at 22:18
  • Ok, got it your code was java. When I tanslated into python it worked like a charm. – crocefisso Apr 24 '16 at 00:42
1

Python client driver version :

r.db('base').table('table').group('city').count().ungroup().filter(lambda c: c['reduction'].ge(96)).order_by(r.desc('reduction')).run()
crocefisso
  • 557
  • 1
  • 5
  • 20