Exercise 1
Insert (Insert_one, Insert_many), Update, Delete
Use a ex1 database and imdb collection.
We are going to make a movie database like IMDb.
Each movie has following information.
title: String
director: String
genre: List(String)
score: Double
Insert a movie
Write a script that inserts movie information to a movie collection.
Type the movie information as follows:
Movie Title: Avengers: Infinity War
Director: Anthony Russo and Joe Russo
Genre: Action, Adventure, Drama
score: 8.6
[INFO] Success to insert!
Plain: Terminal output
Bold: User input
Hint: use a input() function
Confirm that the insertion is operated properly.
Print only movie’s title(s)
[INFO] Movie list
Avengers: Infinity War
Insert three movies more. Use insert_many
Movie Title: Bohemian Rhapsody
Director: Bryan Singer
Genre: Biography, Drama, Music
score: 8.1
Quit (Y/n)? n
Movie Title: Happy Death Day 2U
Director: Christopher Landon
Genre: Drama, Horror, Mystery
score: 6.6
Quit (Y/n)? n
Movie Title: Spider-Man: Into the Spider-Verse
Director: Bob Persichetti, Peter Ramsey
Genre: Animation, Action, Adventure
score: 8.6
Quit (Y/n)? Y
[INFO] Success to insert!
Confirm that the insertion is operated properly.
Print only movie’s title(s)
[INFO] Movie list
Avengers: Infinity War
Bohemian Rhapsody
Happy Death Day 2U
Spider-Man: Into the Spider-Verse
Update movie information
Querying movie title and update the information
[INFO] Enter the information which you want to edit
Movie Title: Avengers: Infinity War
Director: Anthony Russo and Joe Russo
Genre: Action, Adventure, Drama
score: 8.6
[INFO] Success to update!
Plain: Terminal output
Bold: query
Italic: update
Print all documents
[INFO] Movie list
[{'_id': ObjectId('5c76acb565d1016cd33d4a5d'),
'director': 'Anthony Russo and Joe Russo',
'genre': ['Action', ' Adventure', ' Drama'],
'score': 8.6,
'title': 'Avengers: Infinity War'},
{'_id': ObjectId('5c76ad0d65d1016cd33d4a5e'),
'director': 'Bryan Singer',
'genre': ['Biography', ' Drama', ' Music '],
'score': 8.1,
'title': 'Bohemian Rhapsody'},
{'_id': ObjectId('5c76ad0d65d1016cd33d4a5f'),
'director': 'Christopher Landon',
'genre': ['Drama', ' Horror', ' Mystery'],
'score': 6.6,
'title': 'Happy Death Day 2U'},
{'_id': ObjectId('5c76ad0d65d1016cd33d4a60'),
'director': 'Bob Persichetti, Peter Ramsey',
'genre': ['Animation', ' Action', ' Adventure'],
'score': 8.6,
'title': 'Spider-Man: Into the Spider-Verse'}]
Remove movie (Plain: Output, Bold: User input)
Remove a document
[INFO] Enter the title which you want to remove
Movie Title: Happy Death Day 2U
[INFO] Are you sure? (Y/n) Y
[INFO] Deleted
Result
[INFO] Movie list
Avengers: Infinity War
Bohemian Rhapsody
Spider-Man: Into the Spider-Verse
Last updated
Was this helpful?