Last active
September 1, 2020 14:29
-
-
Save fmasanori/5903005 to your computer and use it in GitHub Desktop.
CRUD MongoDB Python2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from pymongo import MongoClient | |
connection = MongoClient("mongodb://localhost") | |
db = connection.test | |
post = {"title": "My Blog Post", | |
"content": "Here's my blog post.", | |
"date": datetime.utcnow()} | |
db.blog.insert_one(post) | |
print ("find retorna um cursor") | |
cursor = db.blog.find() | |
for d in cursor: | |
print (d) | |
print ("find_one retorna um documento") | |
d = db.blog.find_one() | |
print (d) | |
db.blog.delete_one({"title": "My Blog Post"}) | |
print ("depois de remover o post") | |
d = db.blog.find_one() | |
print (d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment