{ Flight: "1", ArrDelayMinutes :"3.0"} ,
{ Flight:"1", ArrDelayMinutes:"16.0"},
{Flight:"2", ArrDelatMinutes:"15.0"}
List the total number of delayed arrival flights in the dataset. A delayed arrival flight or plane is one whose ArrDelayMinutes is greater than 15
CodePudding user response:
You can use aggregation like following
$match
to filter your expected result. Refer when can you use $expr$group
to find total using$sum
by 1
Here is the code
db.collection.aggregate([
{
"$match": {
$expr: {
$gt: [
{ $toDouble: "$ArrDelayMinutes" },
15.0
]
}
}
},
{
"$group": {
"_id": null,
"total": { "$sum": 1 }
}
}
])
Working Mongo playground