From 57d2ad3e6da20246d679b55939dddf97c66f081a Mon Sep 17 00:00:00 2001 From: DJYohann Date: Wed, 17 May 2023 11:26:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20-=20update=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f2a2201 --- /dev/null +++ b/README.md @@ -0,0 +1,156 @@ +# Client Serveur - TP1 + +## 💻 Queries + +### Introduction + +**Récupération des samples** + +```sh +curl https://github.com/neelabalan/mongodb-sample-dataset/blob/main/sample_mflix/movies.json --output movies.json +curl https://github.com/neelabalan/mongodb-sample-dataset/blob/main/sample_mflix/comments.json --output comments.json +``` + +**Création de la base de données** + +``` +use tp1 +``` + +**Création des collections** + +``` +db.createCollection("movies"); +db.createCollection("comments"); +``` + +**Import des fichiers JSON** + +``` +mongoimport --collection movies movies.json --db tp1 +mongoimport --collection comments comments.json --db tp1 +``` + +### 1 - Compter le nombre de Thriller présents en base (films qui possèdent au moins le genre Thriller) + +```SQL +db.movies.countDocuments({ + genres: "Thriller" +}); +``` + +ou + +```SQL +db.movies.aggregate([ + { $match: { genres: "Thriller" } }, + { $count: "Number contains Thriller in genres" } +]); +``` + +### 2 - Trouver la liste des films qui contiennent le mot "ghost" dans leur titre + +#### Case sensitive + +```SQL +db.movies.find({ + title: /.*ghost.*/ +}); +``` + +#### Case insensitive + +```SQL +db.movies.find({ + title: /.*ghost.*/i +}); +``` + +### 3 - Trouver la liste des films qui contiennent le mot "ghost" dans leur titre et qui sont sortis après 2013 + +#### Case sensitive + +```SQL +db.movies.find({ + title: /.*ghost.*/, + year: { $gt: 2013 }, +}); +``` + +#### Case insensitive + +```SQL +db.movies.find({ + title: /.*ghost.*/i, + year: { $gt: 2013 }, +}); +``` + +### 4 - Trouver le film qui a gagné le plus de récompenses + +```SQL +db.movies.aggregate([ +{ + $match: { "awards.wins": { $exists: true } } +}, +{ + $sort: { "awards.wins": -1 } +}, +{ + $limit: 1 +} +]); +``` + +### 5 - Trouver le plus vieux film de plus de 2 heures ayant une note inférieur à 2 sur la plateforme imdb + +```SQL +db.movies.aggregate([ +{ + $match: { + "runtime": { $exists: true }, + "imdb.rating": { $exists: true }, + } +}, +{ + $match: { + "runtime": { $gt: 120 }, + "imdb.rating": { $lt: 2 }, + } +} +]); +``` + +### 6 - Modifier la requête précédente pour récupérer en même temps les commentaires. + +``` +db.movies.aggregate([ +{ + $match: { + "runtime": { $exists: true }, + "imdb.rating": { $exists: true }, + } +}, +{ + $match: { + "runtime": { $gt: 120 }, + "imdb.rating": { $lt: 2 }, + } +}, +{ + $lookup: { + from: "comments", + localField: "_id", + foreignField: "movie_id", + as: "movie_comments" + } +} +]); +``` + +## 👨‍💻 Author + +**BREUIL Yohann** + +* GitHub: [@DJYohann](https://github.com/DJYohann) +* LinkedIn: [@BREUIL Yohann](https://www.linkedin.com/in/yohann-breuil-02b18a165/) \ No newline at end of file