# Week3 Quiz2.

For this quiz, create a file named `dbmovie.py` and start with the code below.

```
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.grgzlle.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta
```

<hr>

### Quiz1. What's the review point of '가버나움'?
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660662070723/jeUFdliBB.png align="left")

> when looking for a certain data, use `user = db.users.find_one({'name':'bobby'})`

- `Print(movie)` first.

```
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.grgzlle.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

movie = db.movies.find_one({'title':'가버나움'})
print(movie)
```
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660662210573/HpcluQIZa.png align="left")

- We only need 'star'

```
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.grgzlle.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

movie = db.movies.find_one({'title':'가버나움'})
print(movie['star'])
```

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660662241360/V4Jrn56mD.png align="left")

<hr>

### Quiz2. Show me all the movie titles that have the same review score as 가버나움.
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660662303026/ZWu8vWRrl.png align="left")

- define `star`

```
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.grgzlle.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

movie = db.movies.find_one({'title':'가버나움'})
star = movie['star']
```

- To find all data, use
`all_users = list(db.users.find({},{'_id':False}))`

`all_movies = list(db.movies.find({'star':star},{'_id':False}))`


- use `for` statement and print.

```
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.grgzlle.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

movie = db.movies.find_one({'title':'가버나움'})
star = movie['star']

all_movies = list(db.movies.find({'star':star},{'_id':False}))

for m in all_movies:
    print(m)
```
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660662779618/v1o7IrqK4.png align="left")


- As a result, we want to see only the titles.

```
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.grgzlle.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

movie = db.movies.find_one({'title':'가버나움'})
star = movie['star']

all_movies = list(db.movies.find({'star':star},{'_id':False}))

for m in all_movies:
    print(m['title'])
```
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660662819697/S4Grs7K_2.png align="left")


<hr>

### Quiz3. Make the review point of 가버나움 0.
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1660663103388/_q0Tp8dye.png align="left")

- To update data, use
`db.users.update_one({'name':'bobby'},{'$set':{'age':19}})`

`db.movies.update_one({'title':'가버나움'},{'$set':{'star':'0'}})`

```
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.grgzlle.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta

db.movies.update_one({'title':'가버나움'},{'$set':{'star':'0'}})
```










