1

I would like to retrieve the names of all the nested keys present in all the documents in a given mongodb collection.

E.g.:

> db.sample.insert({account: 'abc', account_type: 'individual', properties: 
     {title: 'mr', gender: 'M', dob: '19850101' }});
> db.sample.insert({account: 'xyz', account_type: 'individual', properties: 
     {title: 'ms', gender: 'F' }}); 
> db.sample.insert({account:'lmn', account_type: 'business', properties: 
     {title: 'messrs', industry: 'telecom', estd_on: '19850301' }});

I would like to get the unique keys (including all the nested keys) like:

[account, account_type, properties.title, properties.gender, properties.dob, properties.industry, properties.estd_on]

skrisshnaswamy
  • 149
  • 1
  • 9
  • 1
    Possible duplicate of [MongoDB Get names of all keys in collection](http://stackoverflow.com/questions/2298870/mongodb-get-names-of-all-keys-in-collection) – Blakes Seven Nov 16 '15 at 06:58
  • I had tried the solution provided in this link. But the issue is, it just lists out only the keys at the _id level and does not lists out the nested keys. – skrisshnaswamy Nov 16 '15 at 07:35
  • There is more than one answer there than the accepted answer. The accepted answer is old and people have added to this since. – Blakes Seven Nov 16 '15 at 07:41
  • Thanks!... I was infact looking for a mongodb solution and most solution discussed there were either using python or js.. But it appears that there is no direct mongodb solution for the same. So, I've decided to go with the js solution - the [variety](https://github.com/variety/variety) library. – skrisshnaswamy Nov 16 '15 at 10:50

0 Answers0