BC2402 Week 10 Class Exercises
BC2402 Week 10 Class Exercises
Sem: 9
Group: 7
Required:
Required:
1. Insert the following documents using upsert, not insert( ).
{
"title" : "Nanyang United",
"requiresTeam" : true
},
{
"title" : "Sengkang One",
"requiresTeam" : false
}
use sports
db.teams.updateMany(
,{upsert:true})
db.teams.updateMany(
,{upsert:true})
db.teams.find()
2. Update all documents which do require a team by adding a new field with the minimum amount
of players required.
db.teams.updateMany(
{"requiresTeam" : true},
{$set: {"MinNoPlayers" : 0}}
,{upsert:true})
3. Update all documents that require a team by increasing the number of required players by 10.
db.teams.updateMany(
{"requiresTeam" : true},
Required:
Build a pipeline to find the number of person(s) older than 50. Group these people by gender. For each
group, compute the average age and count the total number of person(s) in the group. Order the
output by the total amount of person(s) per group in a descending order.
use "analytics"
db.persons.find()
db.persons.aggregate([
{$match: {"dob.age":{$gt: 50}}},
{$group: { _id: "$gender", avgAge: {$avg: "$dob.age"}, totalCount: {$sum:1}}},
{$sort: {totalCount: -1}}
])