Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rethinkdb: Chain getAll & between

Tags:

rethinkdb

I get RqlRuntimeError: Expected type TABLE_SLICE but found SELECTION: error when chaining getAll and between methods.

r.db('mydb').table('logs') .getAll('1', {index: 'userId'}) .between(r.time(2015, 5, 1, 'Z'), r.time(2015, 5, 4, 'Z'), {index: 'createdAt'})

Is there a way to use index(es) when querying for data that belongs to userId=1 and where createdAt is between dates? As I understand filter does not use indexes.

like image 888
xpepermint Avatar asked May 23 '26 19:05

xpepermint


1 Answers

You can't use two indexes like that, but you can create a compound index:

r.table('logs').indexCreate('compound', function(row) {
  return [row('userId'), row('createdAt')];
})
r.table('logs').between([1, firstTime], [1, secondTime], {index: 'compound'})
like image 77
mlucy Avatar answered May 30 '26 16:05

mlucy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!