Robert Zaremba
Robert Zaremba

Reputation: 8481

How to specify ordering in rethinkdb between query using index

I want to do something like the following:

r.db('mydb').table('tab').between( ['s', 0], ['s', 99999], {index: r.desc('s-t')})

but this is not a correct Rql query:

RqlCompileError: DESC may only be used as an argument to ORDERBY. in:

Can I safely use

r.db('mydb').table('tab').between( ['s', 0], ['s', 99999], {index: 's-t'}).orderBy({index: r.desc('s-t')})

Will it be executed optimally (using single read instead of reading all records and then sorting them?

Upvotes: 1

Views: 680

Answers (1)

neumino
neumino

Reputation: 4353

Yes, if you chain a between command with an orderBy one (using the same index), it will be executed in an efficient way.

Upvotes: 1

Related Questions