I have documents in an otherwise empty RethinkDB table called numbers
below containing nested objects. I create a secondary index, a compound and a multi index, on a pair of numbers inside the inner object. Compound because I want to use 2-element arrays as secondary indexes, and multi because the same 2-pair might correspond to multiple documents.
Here, I create that secondary index and insert some documents in the Data Explorer browser view:
r.db('test')
.table('numbers')
.indexCreate('idx', [ r.row('group')('a'), r.row('group')('b') ],
{multi : true});
r.db('test').table('numbers').insert([
{name : 'Foo', group : {a : 2, b : 3}},
{name : 'Bar', group : {a : 2, b : 9}},
{name : 'Baz', group : {a : 2, b : 3}},
{name : 'Qwer', group : {a : 4, b : 4}}
]);
Now I go to run a query using between
. For this example, I expect to see three documents returned, but instead I get no documents back:
r.db('test').table('numbers').between([ 2, 0 ], [ 3, 5 ], {index : 'idx'});
// No results returned.
Confused, I tested this secondary index with just scalar lookups (so pretending idx
isn't a compound index): that returns documents!
r.db('test').table('numbers').between(2, 3, {index : 'idx'})
// 3 rows returned: Foo, Bar, Baz
What? Why would treating the idx
secondary array as a scalar index (rather than arrays) and return three documents? What happened to my compound index?
Setting rightBound
to closed
doesn't seem to do anything. Also, building the index key using a function, i.e., passing function(obj) {return [obj('group')('a'), obj('group')('b')];}
to indexCreate
didn't make a diference.
I've tested another compound multi-index whose keys are [string, number, number], and between
works great for that multi case: it finds documents. Why won't the two-number multi case work here?