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

78 lines
3.1 KiB

7 months ago
sols = ['db.movies.find({year: 1928}, {_id: 0, title: 1, plot: 1})',
"""db.movies.find({'awards.wins' :{$gt: 200}}, {_id: 0, title: 1, 'awards_wins': '$awards.wins'})""",
"""db.movies.find({'imdb.votes' :{$gt: 100}, 'imdb.rating':{$gt: 9.0}}, {_id: 0, title: 1, 'imdb.votes': 1, 'imdb.rating':1})""",
"""
db.movies.aggregate([{$unwind: '$directors'},
{$match: {year: {$gte: 1915, $lte: 1920}}},
{$group: {_id: '$directors', count_of_movies: {$sum: 1}}},
{ $sort: {count_of_movies: -1} }
])
""",
"""
db.comments.aggregate([
{ $lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{ $unwind: "$MovieDetails" },
{$project: {name:1, "Movie_imdb_rating": "$MovieDetails.imdb.rating"}},
{$group: {_id: '$name', count_of_comments: {$sum:1}, average_movie_ratings: {$avg: "$Movie_imdb_rating"}}},
{$match: {count_of_comments: {$gt: 250}}}
])
""",
("""
db.movies.aggregate([
{$unwind: "$cast"},
{$match: {year:1996}},
{$project: {cast: 1}},
{$group: {_id: "$cast", CountOfMovies: {$sum:1}}},
{$match: {CountOfMovies:{$gt: 3}}},
{ $sort: {CountOfMovies: -1} }
])
""",
"""
db.movies.aggregate([
{$unwind: "$cast"},
{$match: {year:1996}},
{$project: {cast: 1}},
{$group: {_id: "$cast", CountOfMovies: {$sum:1}}},
{$match: {CountOfMovies:{$gte: 3}}},
{ $sort: {CountOfMovies: -1} }
])
"""),
("""
db.comments.aggregate([
{ $lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{$unwind: '$MovieDetails'},{$unwind: '$MovieDetails.genres'},
{$group: {_id: {name: '$name', Genres: '$MovieDetails.genres'}, comment_count: {$sum: 1}}},
{$match:{"_id.Genres": "Crime", comment_count:{$gt: 35}}},
{$project: {_id:0, name : "$_id.name", comment_count: 1}}
])
""",
"""
db.comments.aggregate([
{ $lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{$unwind: '$MovieDetails'},{$unwind: '$MovieDetails.genres'},
{$group: {_id: {name: '$name', Genres: '$MovieDetails.genres'}, comment_count: {$sum: 1}}},
{$match:{"_id.Genres": "Crime", comment_count:{$gte: 35}}},
{$project: {_id:0, name : "$_id.name", comment_count: 1}}
])
"""),
"""
db.movies.aggregate([
{$unwind: '$cast'},
{$unwind: '$directors'},
{$match: {$expr: {$eq: ["$cast", "$directors"]}}},
{$project: {title:1, directors: 1}}
])
"""]