From 169ceab445d1354a00d13e93655a453fb6bf0b47 Mon Sep 17 00:00:00 2001 From: "ismail.taha_janan" Date: Sun, 21 May 2023 15:13:06 +0200 Subject: [PATCH] first --- README.md | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5234ba3 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +# Clent-server TP + +## Run Docker + +``` +docker cp /Users/etudiant/Downloads/mongodb-sample-dataset-main/sample_mflix test-mongo:/movies +``` + +``` +mongoimport --db movies --collection collection /movies/movies.json +``` + +list containers + +``` +docker container ls +``` + +run container +``` +docker exec -it [ContainerID] bash +``` + +lancer la DB +``` +mongosh +``` + +``` +db.collection.count({genres: { $in: ["Thriller" ] }}); +``` + +``` +db.collection.find({title:{$regex : /ghost/i}}); +``` + + +``` +db.collection.find({title:{$regex : /ghost/i},year: { $gt: 2013 }}); +``` + +``` +db.movies.aggregate([ + { "$sort": { "awards.wins": -1 } }, + { "$limit": 1 } +]) +``` + +``` +db.movies.aggregate([ + { "$match": { "runtime": { "$gt": 120 }, "imdb.rating": { "$lt": 2.0 }}}, + { "$sort": { "year": 1 } }, + { "$limit": 1 } +]) +``` + + +``` +db.movies.aggregate([ + { "$match": { "runtime": { "$gt": 120 }, "imdb.rating": { "$lt": 2.0 } } }, + { "$sort": { "year": 1 } }, + { "$limit": 1 }, + { "$lookup": { + "from": "comments", + "localField": "_id", + "foreignField": "movie_id", + "as": "movie_comments" + }} +]) +``` + +``` +db.movies.aggregate([ + { "$unwind": "$countries" }, + { + "$group": { + "_id": "$countries", + "count": { "$sum": 1 }, + "titles": { "$push": "$title" } + } + }, + { + "$project": { + "_id": 0, + "country": "$_id", + "count": 1, + "titles": 1 + } + }, + { "$sort": { "count": -1 } } +]) +``` \ No newline at end of file