You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
autograders/mongodb/source/solution.py

48 lines
2.8 KiB

sols = ['db.bills.find({sponsor_name:"Marco Rubio"}, {_id:0, title: 1, sponsor_name:1, sponsor_state:1})',
'db.bills.find({cosponsors:{$gte:3, $lte:5}}, {_id:0, title:1, sponsor_name:1, cosponsors:1})',
'db.bills.find({$or:[{cosponsors:{$gte:3, $lte:5}}, {sponsor_name:"Marco Rubio"}]}, {_id:0, title:1, sponsor_name:1, cosponsors:1})',
'''db.congress.aggregate([
{ $match: {"state": "IN"} },
{ $group: {_id: "$role_type", count_of_this_role: {$sum:1} } },
{ $sort: {count_of_this_role: -1} },
{ $project: {_id: 1, count_of_this_role: 1} }
])''',
'''db.bills.aggregate([
{ $lookup: {
from: "congress",
localField: "sponsor_id",
foreignField: "person.bioguideid",
as:"congressMember"} },
{ $unwind: "$congressMember" },
{ $project: {_id: 0, title:1, sponsor_name: 1, "description": "$congressMember.description", "DOB": "$congressMember.person.birthday"} }
])''',
'''db.bills.aggregate([
{ $unwind: "$committee_codes" },
{ $project: {committee_codes: 1} },
{ $group: {_id: "$committee_codes", countOfCommittee: {$sum:1} } },
{ $sort: {countOfCommittee: -1} },
])''',
'''db.bills.aggregate([
{ $project: {_id: 1, title:1, sponsor_name: 1, sponsor_state:1}},
{ $lookup: {
from: "bills",
localField: "sponsor_state",
foreignField: "sponsor_state",
as:"otherBills"} },
{ $unwind: "$otherBills" },
{ $project: {title: 1, sponsor_name: 1, sponsor_state: 1, otherbill_id: "$otherBills._id", otherbill_title: "$otherBills.title", otherbill_sponsor_name: "$otherBills.sponsor_name", otherbill_sponsor_state: "$otherBills.sponsor_state"}},
{ $match: {$expr: {$lt: ["$_id", "$otherbill_id"]}}}
])''',
'''db.congress.aggregate([
{ $project: {_id: 1, firstname: "$person.firstname", lastname: "$person.lastname", state: 1}},
{ $lookup: {
from: "congress",
localField: "lastname",
foreignField: "person.lastname",
as:"otherPersons"} },
{ $unwind: "$otherPersons" },
{ $match: {$expr: {$lt: ["$_id", "$otherPersons._id"]}}},
{ $project: {_id:1, firstname: 1, lastname: 1, state:1, otherPerson_id: "$otherPersons._id", otherPerson_firstname: "$otherPersons.person.firstname", otherPerson_lastname: "$otherPersons.person.lastname", otherPerson_state: "$otherPersons.state"}},
{ $match: {$expr: {$eq: ["$state", "$otherPerson_state"]}}},
])''']