Narwhal
Narwhal

Reputation: 784

Getting list of fields from a table

I understand this command will produce a list of fields ("keys") for a given "document"

r.table('users').get(1).keys()

My question: Is there a command that gives all possible unique key names for all of the documents?

Upvotes: 1

Views: 758

Answers (1)

  1. keys.
  2. map it.
  3. reduce it.
  4. distinct on result array.

Query:

r.table('users').map(function(doc){
  return doc.keys();
}).reduce(function(uniq, doc){
  return uniq.setUnion(doc);
}).distinct()

Upvotes: 3

Related Questions