PyCharm_Aufgabe1
In [ ]:
Copied!
! pip install -qU pymongo==4.6.2
! python -m pip install "pymongo[srv]"==3.12
! pip install -qU pymongo==4.6.2
! python -m pip install "pymongo[srv]"==3.12
In [ ]:
Copied!
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
In [ ]:
Copied!
print(myclient.list_database_names())
print(myclient.list_database_names())
In [ ]:
Copied!
print(myclient.list_database_names())
print(myclient.list_database_names())
In [ ]:
Copied!
print(myclient.list_database_names())
print(myclient.list_database_names())
In [ ]:
Copied!
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
mycol = mydb["movies"]
movielist = [{
"title": "Rocky",
"releaseDate": "1976-12-03",
"genre": "Action",
"about": "A small-time boxer gets a supremely rare chance to fight aheavy-weight champion in a bout in which he strives to go the distance for his self-respect.",
"countries": ["USA"],
"cast": ["Sylvester Stallone", "Talia Shire", "Burt Young"],
"writers": ["Sylvester Stallone"],
"directors": ["John G. Avildsen"]
}, {
"title": "Rambo 4",
"releaseDate": "2008-01-25",
"genre": "Action",
"about": "In Thailand, John Rambo joins a group of mercenaries to venture into war-torn Burma, and rescue a group of Christian aid workers who were kidnapped by the ruthless local infantry unit.",
"countries": ["USA"],
"cast": [" Sylvester Stallone", "Julie Benz", "Matthew Marsden"],
"writers": ["Art Monterastelli", "Sylvester Stallone"],
"directors": ["Sylvester Stallone"]
}]
movies = mycol.insert_many(movielist)
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
mycol = mydb["movies"]
movielist = [{
"title": "Rocky",
"releaseDate": "1976-12-03",
"genre": "Action",
"about": "A small-time boxer gets a supremely rare chance to fight aheavy-weight champion in a bout in which he strives to go the distance for his self-respect.",
"countries": ["USA"],
"cast": ["Sylvester Stallone", "Talia Shire", "Burt Young"],
"writers": ["Sylvester Stallone"],
"directors": ["John G. Avildsen"]
}, {
"title": "Rambo 4",
"releaseDate": "2008-01-25",
"genre": "Action",
"about": "In Thailand, John Rambo joins a group of mercenaries to venture into war-torn Burma, and rescue a group of Christian aid workers who were kidnapped by the ruthless local infantry unit.",
"countries": ["USA"],
"cast": [" Sylvester Stallone", "Julie Benz", "Matthew Marsden"],
"writers": ["Art Monterastelli", "Sylvester Stallone"],
"directors": ["Sylvester Stallone"]
}]
movies = mycol.insert_many(movielist)
In [ ]:
Copied!
print(movies.inserted_ids)
for movies in mycol.find():
print(movies)
print(movies.inserted_ids)
for movies in mycol.find():
print(movies)
In [ ]:
Copied!
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
mycol = mydb["awards"]
awardslist = [{
"title": "Oscars",
"year": "1976",
"category": "Best Film",
"nominees": ["Rocky","All The President's Men","Bound For Glory","Network","Taxi Driver"],
"winners" :
[
{
"movie" : "Rocky"
}
]
}, {
"title": "Oscars",
"year": "1976",
"category": "Actor In A Leading Role",
"nominees": ["PETER FINCH","ROBERT DE NIRO","GIANCARLO GIANNINI","WILLIAM HOLDEN","SYLVESTER STALLONE"],
"winners" :
[
{
"actor" : "PETER FINCH",
"movie" : "Network"
}
]
}]
awards = mycol.insert_many(awardslist)
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
mycol = mydb["awards"]
awardslist = [{
"title": "Oscars",
"year": "1976",
"category": "Best Film",
"nominees": ["Rocky","All The President's Men","Bound For Glory","Network","Taxi Driver"],
"winners" :
[
{
"movie" : "Rocky"
}
]
}, {
"title": "Oscars",
"year": "1976",
"category": "Actor In A Leading Role",
"nominees": ["PETER FINCH","ROBERT DE NIRO","GIANCARLO GIANNINI","WILLIAM HOLDEN","SYLVESTER STALLONE"],
"winners" :
[
{
"actor" : "PETER FINCH",
"movie" : "Network"
}
]
}]
awards = mycol.insert_many(awardslist)
In [ ]:
Copied!
print(awards.inserted_ids)
for awards in mycol.find():
print(awards)
print(awards.inserted_ids)
for awards in mycol.find():
print(awards)
In [ ]:
Copied!
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
mycol = mydb["awards"]
mycol.drop()
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["moviesDB"]
mycol = mydb["awards"]
mycol.drop()
In [ ]:
Copied!
mycol = mydb["movies"]
mycol.drop()
mycol = mydb["movies"]
mycol.drop()
In [ ]:
Copied!
mydb = myclient["moviesDB"]
mydb.drop_database
mydb = myclient["moviesDB"]
mydb.drop_database