Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pymongo import MongoClient
- from bson import ObjectId
- client = MongoClient("localhost", 27017)
- db = client["MovieLibrary"]
- collection = db["movies"]
- # CRUD
- # create data
- # collection.insert_one(
- # {
- # "title":"Terminator 2",
- # "language": "eng"
- # }
- # )
- #
- # collection.insert_one(
- # {
- # "title":"Amelie",
- # "language": "fr"
- # }
- # )
- #
- # collection.insert_one(
- # {
- # "title":"Arrival",
- # "language": "eng"
- # }
- # )
- # find data all
- # print([i for i in collection.find()])
- # find by name
- # print(collection.find_one({ "title": "Aliens"}))
- # find by id
- # print(collection.find_one({ "_id": ObjectId('5dbee0fcbdb9649e9fc5b115')}))
- # find by language
- # print([i for i in collection.find({"language":"eng"})])
- # edit data
- # collection.update_one({"_id":ObjectId('5dbee0fcbdb9649e9fc5b115')}, {"$set":{"language":"eng"}})
- # delete
- collection.delete_one({"_id":ObjectId('5dbee0fcbdb9649e9fc5b115')})
Add Comment
Please, Sign In to add comment