0

I want to do something like:

var tab = r.db("test").table("test"); all =[ tab.getAll('1').fitler({'hidden': false}).limit(1), tab.getAll('2').fitler('hidden': false}).limit(1), tab.getAll('3').fitler('hidden': false}).limit(1), ]

But when running this query I'm getting:

Expected type DATUM but found SELECTION:
Robert Zaremba
  • 8,081
  • 7
  • 47
  • 78

1 Answers1

2

In general, the "Expected type DATUM but found SELECTION" error can be solved by adding .coerceTo('array'):

var tab = r.db("test").table("test");
all =[
  tab.getAll('1').filter({'hidden': false}).limit(1).coerceTo('array'),
  tab.getAll('2').filter({'hidden': false}).limit(1).coerceTo('array'),
  tab.getAll('3').filter({'hidden': false}).limit(1).coerceTo('array')
]

But in this specific case, you can replace .limit(1) with .nth(0):

var tab = r.db("test").table("test");
all =[
  tab.getAll('1').filter({'hidden': false}).nth(0),
  tab.getAll('2').filter({'hidden': false}).nth(0),
  tab.getAll('3').filter({'hidden': false}).nth(0)
]
Etienne Laurin
  • 6,731
  • 2
  • 27
  • 31
  • Is it worth to do `.limit(1).nth(0)` together? In otherwords - does rethinkdb use the same optimisation for `nth` as for `limit` in this case? – Robert Zaremba Nov 09 '14 at 12:33