if i need to perform qyery
Number of female and male patient with covid
the two collection are patients ( fname, lname, gender) and encounters (patient, reasondescription)
what is wrong with this query it retrieve the result but without grouping
db.encounters.aggregate([
{$match:{REASONDESCRIPTION:"COVID-19"}},
{
$lookup: {
from: "patients",
let: { patientId:"$PATIENT" },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ["$Id", "$$patientId"] },
],
},
},
},
{$project: {GENDER :1}},
],
as: "patientgender",
},
},
{$group:{_id:"$patientgender", gendercount:{$sum:1} }},
{$project:{gendercount:1}}
])
another query to get the Number of encounters conducted by every provider
db.encounters.aggregate([
{
$lookup: {
from: "providers",
let: { providerid: "$PROVIDER" },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ["$Id", "$$providerid"] },
],
},
},
},
{ $project: { Id:1,
NAME: 1}
},
],
as: "PROVIDERNAMES",
}, },
{$group:{_id:"$PROVIDERNAMES", PROVIDERARR: { $addToSet: "$Id"}}},
{$project:{
PROVIDERCOUNT: {$size : "$PROVIDERARR"} }
}
])
can any one help me where is the problem