I've been learning mongodb and I'm a little stuck writing a query.
I have the following collection:
{
_id : 1,
House: A,
inventory: [
{
place: Kitchen,
item: fridge
},
{
place: Kitchen,
item: stove
},
{
place: Kitchen,
item: TV
},
{
place: Bedroom,
item: bed
},
{
place: Bedroom,
item: TV
}
]
},
{
_id : 2,
House: B,
inventory: [
{
....
}
]
},
How would I write a query to return the count of the "places" and "items"? So the output should be like this:
{id: Kitchen, PlaceCount: 3, itemCount: 3} - 3 kitchen,3 items(fridge,stove,TV)
{id: Bedroom, PlaceCount: 2, itemCount: 2} - 2 Bedroom, 2 items(bed,TV)
I need the TV count to be counted within each place.
{ "_id" : [ "Kitchen", "Kitchen", "Kitchen", "Bedroom", "Bedroom" ], "PlaceCount" : 1, "itemCount" : 1 }, which doesn't make too much sense