practice2db
Assignment:1
- Display all the documents inserted in both the collections.
- Add a value to the rating of the film whose title starts with ‘T’.
- Add an actor named " " in the ‘Actor’ collection. Also add
the details of the film in ‘Film’ collection in which this actor has acted in. - Delete the film " ".
- Delete an actor named " ".
- Delete all actors from an ‘Actor’ collection who have age greater than “ ”
- Update the actor’s address where Actor Id is “ ”.
10.Update the genre of the film directed by “ ”
=========Queries=================
1:db.film.update({"title":/^T/},{$set:{reldetail:[{rating:4}]}})
2:db.actor.insert({actor_id:11,fname:"Shahid",lname:"Kapoor",address:"B-A22 MS House,Malad,Mumbai,Maharashtra,India-342-222",contdet:[{emailId:"[email protected]",phno:1211151338}],age:57})
WriteResult({ "nInserted" : 1 })
3:db.film.insert({film_id:12,title:"Vivah",relyr:2007,genre:["Romantic","Drama"],actors:"Shahid Kapoor",director:["Sooraj Barjatya"],reldetail:[{place:"Mumbai"},{date:"26-07-2007"},"rating 5"]})
WriteResult({ "nInserted" : 1 })
4:db.actor.remove({"fname":"Kareena"})
WriteResult({ "nRemoved" : 1 })
5:db.actor.remove({"age":{$gt:62}})
WriteResult({ "nRemoved" : 1 })
6:> db.actor.update({"actor_id":10},{$set:{"address":"B-A21 Maria House,Andheri-West,Mumbai,Maharashtra,India-342-222"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
Assignment:3
- Find the titles of all the films starting with the letter ‘R’ released during the year
2009 and 2011. - Find the list of films acted by an actor " ".
- Find all the films released in 90s.
- Find all films belonging to “Adventure” and “Thriller” genre.
- Find all the films having ‘A’ rating.
- Arrange the film names in ascending order and release year should be in descending
order. - Sort the actors in ascending order according to their age.
- Find movies that are comedies or dramas and are released after 2013.
- Show the latest 2 films acted by an actor “ ”.
10.List the titles of films acted by actors “ ” and “ ”.
11.Retrieve films with an actor living in Spain.
12.Retrieve films with actor details
=========================================================
Queries
1:db.film.find({and:[{"title":/^T/},{and:[{"relyr":{gte:2007}},{"relyr":{lt:2020}}]}]}).pretty()
{
"_id" : ObjectId("639034b8d0699baa573778a9"),
"film_id" : 11,
"title" : "Tashan",
"relyr" : 2019,
"genre" : [
"Romantic",
"Comedy"
],
"actors" : [
"Ajay Devgan",
"Kareena Kapoor"
],
"director" : [
"Rohit Shetty"
],
"reldetail" : [
{
"rating" : 4
}
]
}
2:db.film.find({"actors":"Shahid Kapoor"},{title:1,_id:0})
{ "title" : "Vivah" }
3:db.film.find({and:[{and:[{"relyr":{gte:1991}},{"relyr":{lt:2000}}]}]},{title:1,_id:0}).pretty()
{ "title" : "Dil Toh Pagal Hai" }
{ "title" : "Anjam" }
{ "title" : "Golmaal 3" }
4:db.film.find({"genre":["Thriller","Adventure"]},{title:1,_id:0}).pretty()
{ "title" : "Golmaal 3" }
5:db.film.find({"reldetail":[{"rating":4}]},{title:1,_id:0}).pretty()
{ "title" : "Tashan" }
6:db.film.find().sort({"title":1},{"relyr":-1},{title:1}).pretty()
{
"_id" : ObjectId("638ee340b11df4fb78e33818"),
"film_id" : 1,
"title" : "3_idiots",
"relyr" : 2003,
"genre" : [
"Romantic",
"Sci-fi"
],
"actors" : [
"AmirKhan",
"KareenaKapoor"
],
"director" : "RohitShetty",
"reldetail" : [
"date 22-10-2003",
"rating 5"
]
}
{
"_id" : ObjectId("638eeb8db11df4fb78e3381f"),
"film_id" : 8,
"title" : "Anjam",
"relyr" : 1995,
"genre" : [
"Romantic",
"Action"
],
"actors" : [
"Madhuri Dixit",
"Sharukh Khan"
],
"director" : [
"Prem Chopda"
],
"reldetail" : [
"date 20-01-1995",
"rating 4.9"
]
}
{
"_id" : ObjectId("638ee436b11df4fb78e33819"),
"film_id" : 2,
"title" : "Baazigar",
"relyr" : 2000,
"genre" : [
"Sci-Fi",
"Adventure"
],
"actors" : [
"SharukhKhan",
"KajolDevgan"
],
"director" : "PareshRawal",
"reldetail" : [
"date 20-02-2000",
"rating 5.1"
]
}
{
"_id" : ObjectId("638ee613b11df4fb78e3381b"),
"film_id" : 4,
"title" : "Brahmastra",
"relyr" : 2022,
"genre" : [
"Sci-Fi",
"Adventure",
"Romantic"
],
"actors" : [
"Ranbir Kapoor",
"AliaBhatt",
"Amitabh Bachchan"
],
"director" : [
"Sajid,Amitabh Bachchan"
],
"reldetail" : [
"date 23-09-2022",
"rating 5"
]
}
{
"_id" : ObjectId("638eea6bb11df4fb78e3381e"),
"film_id" : 7,
"title" : "Dil Toh Pagal Hai",
"relyr" : 1992,
"genre" : [
"Romantic"
],
"actors" : [
"Madhuri Dixit",
"Sharukh Khan"
],
"director" : [
"karan Johar",
"Sajid Nadiadwala"
],
"reldetail" : [
"date 20-12-1992",
"rating 5"
]
}
{
"_id" : ObjectId("638eedb3b11df4fb78e33821"),
"film_id" : 10,
"title" : "Golmaal ",
"relyr" : 2019,
"genre" : [
"Romantic",
"Comedy"
],
"actors" : [
"Ajay Devgan",
"Kareena Kapoor"
],
"director" : [
"Rohit Shetty"
],
"reldetail" : [
{
"place" : [
"Pune",
"Mumbai"
]
},
{
"date" : [
"17-01-2019",
"26-07-2019"
]
},
"rating 3.9"
]
}
{
"_id" : ObjectId("638eec32b11df4fb78e33820"),
"film_id" : 9,
"title" : "Golmaal 3",
"relyr" : 1995,
"genre" : [
"Thriller",
"Adventure"
],
"actors" : [
"Ajay Devgan",
"Kareena Kapoor"
],
"director" : [
"Rohit Shetty"
],
"reldetail" : [
"date 17-01-2019",
"rating 3.9"
]
}
{
"_id" : ObjectId("638ee96fb11df4fb78e3381d"),
"film_id" : 6,
"title" : "Kalank",
"relyr" : 2019,
"genre" : [
"Sci-Fi",
"Thriller",
"Romantic"
],
"actors" : [
"Madhuri Dixit",
"Varun Dhavan"
],
"director" : [
"karan Johar"
],
"reldetail" : [
"date 20-11-2019",
"rating 3"
]
}
{
"_id" : ObjectId("638ee6dcb11df4fb78e3381c"),
"film_id" : 5,
"title" : "STUDENT OF THE YEAR 2",
"relyr" : 2019,
"genre" : [
"Sci-Fi",
"Adventure",
"Romantic"
],
"actors" : [
"Tara Sutaria",
"Ananya Pandey",
"Siddhart Malhotra"
],
"director" : [
"karan Johar"
],
"reldetail" : [
"date 20-11-2019",
"rating 4"
]
}
{
"_id" : ObjectId("639034b8d0699baa573778a9"),
"film_id" : 11,
"title" : "Tashan",
"relyr" : 2019,
"genre" : [
"Romantic",
"Comedy"
],
"actors" : [
"Ajay Devgan",
"Kareena Kapoor"
],
"director" : [
"Rohit Shetty"
],
"reldetail" : [
{
"rating" : 4
}
]
}
{
"_id" : ObjectId("6390380b0dcc962ff67c50eb"),
"film_id" : 12,
"title" : "Vivah",
"relyr" : 2007,
"genre" : [
"Romantic",
"Drama"
],
"actors" : "Shahid Kapoor",
"director" : [
"Sooraj Barjatya"
],
"reldetail" : [
{
"place" : "Mumbai"
},
{
"date" : "26-07-2007"
},
"rating 5"
]
}
7: db.actor.find().sort({age:1}).pretty()
{
"_id" : ObjectId("638ef601b11df4fb78e3382b"),
"actor_id" : 9,
"fname" : "Alia",
"lname" : "Bhatt",
"address" : "Fl-501,RK plaza,Baner,Pune,Maharashtra,India-395-242",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 7821123366
}
],
"age" : 32
}
{
"_id" : ObjectId("638ef2f0b11df4fb78e33826"),
"actor_id" : 5,
"fname" : "Siddharth",
"lname" : "Malhotra",
"address" : "B-23,Simona benzers,Andheri-West,Mumbai,Maharashtra,India-394-387",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 7821788123
}
],
"age" : 38
}
{
"_id" : ObjectId("638ef346b11df4fb78e33827"),
"actor_id" : 4,
"fname" : "Varun",
"lname" : "Dhavan",
"address" : "Fl-501,VD House,Andheri-East,Mumbai,Maharashtra,India-394-477",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 7821788337
}
],
"age" : 38
}
{
"_id" : ObjectId("638ef1cab11df4fb78e33824"),
"actor_id" : 3,
"fname" : "Ranbir",
"lname" : "Kapoor",
"address" : "Fl-501,RK plaza,Baner,Pune,Maharashtra,India-395-242",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 7821123337
}
],
"age" : 45
}
{
"_id" : ObjectId("638ef0bbb11df4fb78e33822"),
"actor_id" : 1,
"fname" : "Amir",
"lname" : "Khan",
"address" : "201,Surya Plaza,Andheri,Mumbai,Maharashtra,India-394-211",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 8988123453
}
],
"age" : 50
}
{
"_id" : ObjectId("638ef3ddb11df4fb78e33828"),
"actor_id" : 6,
"fname" : "Kajol",
"lname" : "Devgan",
"address" : "B-A21 Maria House,Thane,Mumbai,Maharashtra,India-342-222",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 1211788337
}
],
"age" : 55
}
{
"_id" : ObjectId("6390374d0dcc962ff67c50ea"),
"actor_id" : 11,
"fname" : "Shahid",
"lname" : "Kapoor",
"address" : "B-A22 MS House,Malad,Mumbai,Maharashtra,India-342-222",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 1211151338
}
],
"age" : 57
}
{
"_id" : ObjectId("638ef5a3b11df4fb78e3382a"),
"actor_id" : 8,
"fname" : "Nandamuri",
"lname" : "Rao",
"address" : "B-J12,Ntr Bunglows,Banglore,Karnataka,India-348-100",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 1281799337
}
],
"age" : 60
}
{
"_id" : ObjectId("638ef64bb11df4fb78e3382c"),
"actor_id" : 10,
"fname" : "Ajay",
"lname" : "Devgan",
"address" : "B-A21 Maria House,Andheri-West,Mumbai,Maharashtra,India-342-222",
"contdet" : [
{
"emailId" : "[email protected]",
"phno" : 1211151337
}
],
"age" : 62
}
8:db.film.find({and:[{and:[{"genre":["Romantic","Comedy"]},{"relyr":{$gte:2013}}]}]},{title:1,_id:0}).pretty()
{ "title" : "Golmaal " }
{ "title" : "Tashan" }
9: db.film.find({"actors":"Ranbir Kapoor"},{title:1,_id:0}).sort({"relyr":-1}).limit(2)
{ "title" : "Brahmastra" }
10: db.film.find({"actors":["Madhuri Dixit","Sharukh Khan"]},{title:1,_id:0})
{ "title" : "Dil Toh Pagal Hai" }
{ "title" : "Anjam" }
11: