I have a deeply nested collection in my MongoDB collection.
When I run the following query:
db.countries.findOne({},{'data.country.neighbor.name':1,'_id':0})
I end up with this nested result here:
{"data" : {
"country" : [
{
"neighbor" : [
{
"name" : "Austria"
},
{
"name" : "Switzerland"
}
]
},
{
"neighbor" : {
"name" : "Malaysia"
}
},
{
"neighbor" : [
{
"name" : "Costa Rica"
},
{
"name" : "Colombia"
}
]
}
]
}}
Now, this is what I want:
['Austria', 'Switzerland', 'Malaysia', 'Costa Rica', 'Colombia']
or this:
{'name':['Austria', 'Switzerland', 'Malaysia', 'Costa Rica', 'Colombia']}
or anything else similar... Is this possible?