My collections contain documents with numerous lists of maps. E.g
{
name : 'Ned',
mapList :
[
{
type : 'DVD',
sales : 100
},
{
type : 'CD',
sales : 200
}
]
}
Is there a way to list the keys of the documents in the mapList attribute?
I've come across this problem before with the document itself and used map reduce as a solution following the answer listed here : MongoDB Get names of all keys in collection
Is it possible to use map reduce here or is there another way? Note* I can't change the my document structure
Edit - My current approach and output
mr = db.runCommand({
"mapreduce" : "entertainmentStats",
"map" : function() {
for (var key in this.mapList) { emit(key, null); }
},
"reduce" : function(key, stuff) { return null; },
"out": "entertainmentStats" + "_keys"
})
The approach is identitcal to that of the answer listed in ly linked question except that I'm tring to perform the map reduce operation on the mapList attribute of the documents. My output keys are always null.
I've attempted the same approach with a single map element in a collection and it worked fine but it doesn't work for the array of maps