Querying a Riak DB by a Subkey

66 Views Asked by At

I'm using riak-js and node.js

If I have a document as follows:

 { 'skey1': 'val1',
   'skey2': 'val2',
     ......,
   'skeyn': 'valn'
  }

How can I return a document that has skey2 = 'val2'? How would this be done in node.js / riak-js?

1

There are 1 best solutions below

0
On

If your storage backend is riak_kv_eleveldb_backend, you can use secondary indexing.

db.save('airlines', 'KLM', {country: 'NL', established: 1919}, {index: {country: 'NL', established: 1919}});

and query like

db.query('airlines', {country: 'NL'});

(the above snippets shamelessly stolen from riak-js.org