1

How can I display the keys from MongoDB in HTML page. I do not want to display the values atached to the keys in UI.

I want to show all the keys but I am not aware how many keys are there in one document.

The DB is nested.

   School:{
           Student : {
                "CATEGORY": "Section1", 
                "Team"    :'A'
              },
           Teacher : { "Experience" : 3,

              }
   }

I want to extract keys Category, Team , Experience

garima
  • 5,154
  • 11
  • 46
  • 77

1 Answers1

0

Using Object.keys?

Object.keys(someCollection.findOne()); //Returns array of strings

Example on the following structure:

{
  _id : ...,
  foo : ...,
  bar : ...
}

Result:

[
  '_id',
  'foo',
  'bar'
]
Kyll
  • 7,036
  • 7
  • 41
  • 64
  • how to do it in nested case – garima May 04 '15 at 11:26
  • Without knowing what kind of result you exactly want, I can only suggest reading this question: http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json – Kyll May 05 '15 at 09:51
  • I want keys like category,experience..nested keys only in html – garima May 05 '15 at 10:22