How to extract multiple queries at once in Rethink

2019-09-05 00:23发布

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:

标签: rethinkdb
1条回答
在下西门庆
2楼-- · 2019-09-05 00:43

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)
]
查看更多
登录 后发表回答