How to extract multiple queries at once in Rethinkdb

空扰寡人 提交于 2019-12-13 03:35:46

问题


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:

回答1:


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)
]


来源:https://stackoverflow.com/questions/26827952/how-to-extract-multiple-queries-at-once-in-rethinkdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!