Untitled
unknown
javascript
2 years ago
2.5 kB
40
Indexable
// General // Question 1 db.movies.count() // Choix 1 db.movies.find().count() // Choix 2 // Question 2 db.movies.aggregate( {$unwind: "$cast"}, {$group: {"_id": "$cast"}}, {$count: "nbr_acteurs"} ) //Question 3 db.movies.aggregate( {$unwind: "$countries"}, {$group: {"_id": "$countries"}}, {$count: "nbr_pays"} ) //Question 4 db.movies.aggregate( {$unwind: "$genres"}, {$group: {"_id": "$genres", "nbr_films": {$sum: 1}}}, {$sort: {"nbr_films": -1}}, {$limit: 5} ) //Question 5 db.movies.aggregate( {$unwind: "$cast"}, {$group: {"_id": "$cast", "nbr_films": {$sum: 1}}}, {$sort: {"nbr_films": -1}}, {$limit: 5} ) //Question 6 db.movies.aggregate( {$unwind: "$countries"}, {$group: {"_id": "$countries", "nbr_films": {$sum: 1}}}, {$sort: {"nbr_films": -1}}, {$limit: 5} ) //Question 7 db.movies.aggregate( {$group: {"_id": "$year", "nbr_films": {$sum: 1}}}, {$sort: {"nbr_films": -1}}, ) // Notation // Question 1 db.movies.aggregate( {$match: {"genres": {$in: ["Drama", "Mystery"]}}} ) // Question 2 db.movies.aggregate( {$match: {"year": {$in: [1998, 2011]}}} ) // Question 3 db.movies.aggregate( {$group: {"_id": "$imdb.rating", "nbr_films": {$sum: 1}}} ) db.movies.aggregate( {$group: {"_id": "$tomatoes.viewer.rating", "nbr_films": {$sum: 1}}} ) db.movies.aggregate( {$group: {"_id": "$tomatoes.critic.rating", "nbr_films": {$sum: 1}}} ) // Question 4 db.movies.aggregate( {$group: {"_id": "$imdb.rating", "nbr_films": {$sum: 1}}}, {$sort: {"_id": -1}} // -1 pour TOP et 1 pour FLOP ) // Question 5 db.movies.aggregate( {$group: {"_id": "$imdb.rating", "nbr_films": {$sum: 1}}}, {$sort: {"_id": -1}}, {$limit: 5} // Choix de la taille ) // Question 6 db.movies.aggregate( {$match: {"genres": {$in: ["Drama", "Mystery"]}, "year": {$in: [1998, 2011]}}}, {$project: {"title": 1, "_id": 0, "year": 1, "imdb.rating": 1} }, {$sort: {"imdb.rating": -1}} // -1 pour TOP et 1 pour FLOP ) // Question 7 db.movies.aggregate( {$match: {"genres": {$in: ["Drama", "Mystery"]}, "year": {$in: [1998, 2011]}}}, {$project: {"title": 1, "_id": 0, "year": 1, "tomatoes.viewer.rating": 1} }, {$sort: {"tomatoes.viewer.rating": -1}} // -1 pour TOP et 1 pour FLOP ) // Question 8 db.movies.aggregate( {$match: {"genres": {$in: ["Drama", "Mystery"]}, "year": {$in: [1998, 2011]}}}, {$project: {"title": 1, "_id": 0, "year": 1, "tomatoes.critic.rating": 1} }, {$sort: {"tomatoes.critic.rating": -1}} // -1 pour TOP et 1 pour FLOP )
Editor is loading...