I want to find distinct values of the cities from a collection containing objects as mentioned below:
{
location:{
address:'XYZ',
city:'New York'
}
}
Can you help me with the query I need to fire? I know I have to use elemMatch and $exists. But my following query seem to work and returns an empty set:
db.collectionName.distinct({'location':{'city':{$exists: true}}})