assignment
assignment
[
{
$match: {
salary:{$gt: 1000000}
}
},
{
$unwind: "$skills"
},
{
$group: {
_id:["$city","$skills"],
roleCount:{$sum:1},
avgsal:{$push:"$salary"},
user:{$push:"$username"},
}
}
2 Group users by age and determine the maximum salary for users with "admin" role
in each age group.
[
{
$match: {
role:"admin"
}
},
{
$group: {
_id: {age:"$age"},
salary:{$max:"$salary"},
userdetail:{$push:
{
username:"$username",
role:"$role",
salary:"$salary"
}
}
}
}
]
3 Group users by role and city, and find the total salary of users with
"JavaScript" as a skill in each subgroup.
[
{
$match: {
skills:"JavaScript"
}
},
{
$group: {
_id:{city:"$city", role: "$role"},
totalsal:{ $avg:"$salary"},
}
}
]
4 Group users by gender and determine the average salary for users with the role
"customer" in each gender.
[
{
$match: {
role:"customer"
}
},
{
$group: {
_id:"$gender",
totalsal:{ $avg:"$salary"},
}
}
]
5 Group users by city and calculate the total number of users with "React" as a
skill in each city.
[
{
$match: {
skills: "React"
}
},
{
$group: {
_id:"$city",
userno:{$sum:1},
userdetails:{$push:"$username"}
}
}
]
6 Group users by role and find the total number of users with "Django" as a skill
in each role.
[
{
$match: {
skills: "Django"
}
},
{
$group: {
_id:"$role",
userno:{$sum:1},
userdetails:{$push:"$username"}
}
}
]
7 Group users by gender and determine the maximum number of skills any user in
each gender possesses.
{
$group: {
_id:"$gender",
maxskill:{$max:"$skills"},
userno:{$sum:1},
userdetails:{$push:"$username"}
}
}
]
8 Group users by age and find the total number of users with "HTML" and "CSS" both
as skills in each age group.
[
{
$match: {
skills:"HTML" , skills:"CSS"
}
},
{
$group: {
_id:"$age",
userno:{$sum:1},
userdetails:{$push:"$username"}
}
}
]
10 Group users by role and gender, and determine the average number of skills
for each subgroup with salary above 1,000,000.