I have a document as follows:
var data={"john:"friend",
"fruit":"banana",
"tv":[{"livingroom":"led",
"bedroom":"lcd"
"fruit":"banana"}]}
and I am trying to return an array of all its unique keys as follows:
["john","fruit,livingroom,bedroom]
so I have the following code:
var mykeys=[];
database.find({},function(result){
result.forEach(function(each){
for (key in each){
mykeys.push(key)
};
}});
But this returns a whole bunch of objects I don't need like:
[$__, isNew, errors, _doc, $__original_save, save, _pres, _posts....]
Is there anyway I can get rid of these keys which aren't in the document?
I am aware of this mapreduce
answer here MongoDB get the names of all the keys in a MongoDB collection but I do not know how to translate it into mongoose. AFAIK mongoose doesn't support runCommand.