Skip to content

Instantly share code, notes, and snippets.

@analytik
Created December 21, 2015 08:31
Show Gist options
  • Select an option

  • Save analytik/e298feb304bf0095e042 to your computer and use it in GitHub Desktop.

Select an option

Save analytik/e298feb304bf0095e042 to your computer and use it in GitHub Desktop.
How to get all RethinkDB table keys and sub-keys (this version does not work recursively)
r.db('test').table('test')
.concatMap(function(doc) {
return doc.keys().map(function(tlKey) {
return r.branch(doc(tlKey).typeOf().eq('OBJECT'),
doc(tlKey).keys().map(function(name){ return r.expr(tlKey).add('.').add(name);}),
tlKey);
});
}).distinct()
/**
* For object
* {
* id: 1,
* username: 'Jhonka',
* email: 'a@b.c',
* address: { street: 'Lorem', city: 'Ipsum' }
* }
*
* the output would be
* [
* 'id',
* 'username',
* 'email',
* [
* 'address.street',
* 'address.city'
* ]
* ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment