> For the complete documentation index, see [llms.txt](https://koonkim.gitbook.io/mongodb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://koonkim.gitbook.io/mongodb/master/crud/challenge/exercise-1.md).

# 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.&#x20;
  * 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&#x20;
  * Bold: User input&#x20;
  * *Hint: use a input() function*

* Confirm that the insertion is operated properly.&#x20;

* Print only movie’s title(s)

```python
[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&#x20;
    >
    > Director: Christopher Landon
    >
    > Genre:  Drama, Horror, Mystery
    >
    > score: 6.6
    >
    > Quit (Y/n)? n
  * > Movie Title: Spider-Man: Into the Spider-Verse&#x20;
    >
    > 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)

```python
[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

```python
[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

```python
[INFO] Movie list
Avengers: Infinity War
Bohemian Rhapsody
Spider-Man: Into the Spider-Verse 
```
