Skip to content

Instantly share code, notes, and snippets.

@neumino
Created October 22, 2013 22:09
Show Gist options
  • Save neumino/7109070 to your computer and use it in GitHub Desktop.
Save neumino/7109070 to your computer and use it in GitHub Desktop.
Multi index -- lexi2
// Data inserted
r.db('test').table('multi').insert({
id:1,
field: [
{key1: 1}, {key1: 2}, {key1: 3}
]
})
r.db('test').table('multi').insert({
id:2,
field: [
{key1: 2}, {key1: 3}, {key1: 4}
]
})
r.db('test').table('multi').insert({
id:3,
field: [
{key1: 5}, {key1: 3}, {key1: 4}
]
})
// Creating the index
r.db('test').table('multi').indexCreate('indexName', function(doc) {
return doc("field").map( function(ob) { return ob("key1")})
}, {multi: true})
// Testing the index
r.db('test').table('multi').getAll(2, {index: 'indexName'}) // return the docs with id 1 and 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment