I am beginner in MongoDB. I need to get individual column counts from one single MongoDB query.
For example I have a collection hotelCollection
with fields cityid , starRating, area, locality
. Now I will pass parameter to cityid
as 123
to the query and I need to fetch the result as:
result: {
starCount: {
1star: 5,
2star: 6,
3star: 5
},
areaCount: {
area1: 4,
area2: 12
},
localityCount: {
locality1: 10,
locality2: 6
}
}
I tried using aggregate
query but I am getting only one column count in the end. So I ended up writing 4 aggregate
queries for the time being. Now I am facing performance issues. I have done lot googling, but couldn't find any solution. Kindly help me out to solve this issue.