Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAll always empty for nested field #4268

Closed
xpepermint opened this issue May 22, 2015 · 3 comments
Closed

getAll always empty for nested field #4268

xpepermint opened this issue May 22, 2015 · 3 comments
Milestone

Comments

@xpepermint
Copy link

Hi. I'm using rethinkdb-2.0.2. When running getAll on secondary index of a nested field always returns no results.

r.db('miner').tableCreate('tracks');
r.db('miner').table('tracks').indexCreate('key');
r.db('miner').table('tracks').indexCreate('identity.key');
r.db('miner').table('tracks').insert({
  key: 2,
  identity: { key: '2' }
});
r.db('miner').table('tracks').getAll('2' {index: 'key'}); // works (the result returns 1 document)
r.db('miner').table('tracks').getAll('2' {index: 'identity.key'}); // not working (no documents)

Is that expected? How can I test that my indexes are working?

@thenightwassave
Copy link

Indexing by nesting fields doesn't work the way you are trying to do it. You need to use:

r.db('miner').table('tracks').indexCreate('indexName', r.row("identity")("key"));

For 'indexName' you could use 'identity.key' but realize it is just a string identifier and has nothing to do with the layout of your document. 'identityKey' or anything else would be just as valid.

More info available at http://rethinkdb.com/api/javascript/index_create/

@deontologician
Copy link
Contributor

Hi @xpepermint this is expected. indexCreate('identity.key') looks for a top level document like {"identity.key": "foo"}, so it won't do what you want. Instead you can use a function to define the index:

r.db('miner').table('tracks').indexCreate('identity.key', r.row('identity')('key'))

Note that identity.key is just a name we gave the index so we can refer to it later, it can be any string you like.

Then you can do queries for it with:

r.db('miner').table('tracks').getAll('2' {index: 'identity.key'})

And it will do what you expect.

Incidentally, a normal key index is really just a function index underneath. These two are identical:

r.table('foo').indexCreate('bar')
r.table('foo').indexCreate('bar', r.row('bar'))

Hope that helps. I'm closing this since it's not a bug, but feel free to ask any more questions you want here and we'll answer them for you.

@deontologician deontologician added this to the notabug milestone May 22, 2015
@xpepermint
Copy link
Author

I missed that part. Thanks!

@danielmewes danielmewes modified the milestones: invalid, notabug Jun 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants