So what I want to do is get the total number of sport activities offered per province per type. For Berlin and Cologne the activities are Running and swimming The output should look something like this:
{
"_id" : {
"province" : "Berlin",
"type" : "Running"
},
"number" : 2.0
}
{
"_id" : {
"province" : "Berlin",
"type" : "Swimming"
},
" number" : 2.0
}
{
"_id" : {
"province" : "Cologne",
"type" : "Running"
},
"number" : 2.0
}
{
"_id" : {
"province" : "Cologne",
"type" : "Swimming"
},
"number" : 1.0
}
my query looks like this, im not getting the result that i want. It shows me the provinces where Running and Swimming are activities which are not Berlin or Cologne. I tried putting the $or insinde a $and and it still didnt produce the outcome i wanted. What am I missing?
db.getCollection("Sport").aggregate([
{$match: {$or: [{province: "Cologne"}, {province: "Berlin"}], $or: [{type: "Running"}, {type: "Swimming"}]}},
{$group: {_id: {province: "$province", type: "$type"}, count: {$sum: 1}}},
{$sort: {count: -1}}
])