Created
October 22, 2013 22:09
-
-
Save neumino/7109070 to your computer and use it in GitHub Desktop.
Multi index -- lexi2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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