Skip to content

Instantly share code, notes, and snippets.

@wojons
Forked from neumino/gist:7109070
Created October 22, 2013 22:19
Show Gist options
  • Save wojons/7109188 to your computer and use it in GitHub Desktop.
Save wojons/7109188 to your computer and use it in GitHub Desktop.
// 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