from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsparta
# insert / find / update / delete
movie = db.movies.find_one({'title':'매트릭스'})
print(movie['star'])
실행결과
C:\Users\rokimo\Desktop\sparta\pythonprac\venv\Scripts\python.exe C:/Users/rokimo/Desktop/sparta/pythonprac/dbquiz.py
9.39
Process finished with exit code 0
target_movies = list(db.movies.find({'star':target_star},{'_id':False}))
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsparta
# insert / find / update / delete
movie = db.movies.find_one({'title':'매트릭스'})
target_star = movie['star']
target_movies = list(db.movies.find({'star':target_star},{'_id':False}))
for target in target_movies:
print(target['title'])
실행결과
C:\Users\rokimo\Desktop\sparta\pythonprac\venv\Scripts\python.exe C:/Users/rokimo/Desktop/sparta/pythonprac/dbquiz.py
인생은 아름다워
매트릭스
라이언 일병 구하기
사운드 오브 뮤직
헬프
포레스트 검프
안녕 베일리
글래디에이터
Process finished with exit code 0
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsparta
# insert / find / update / delete
db.movies.update_one({'title':'매트릭스'},{'$set':{'star':'0'}})
실행결과
C:\Users\rokimo\Desktop\sparta\pythonprac\venv\Scripts\python.exe C:/Users/rokimo/Desktop/sparta/pythonprac/dbquiz.py
Process finished with exit code 0