Created
October 26, 2016 20:28
-
-
Save tiagovizoto/8c0ad3cde83df8083723309e4f7f5ee6 to your computer and use it in GitHub Desktop.
Example MongoDB with Python
This file contains 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 pymongo import MongoClient | |
from time import strftime | |
#model for post | |
post = { | |
"title":"Title of Post", | |
"content":"Content of posts. Text, test. I need Work!!!", | |
"author":"Tiago Vizoto", | |
"date": strftime('%Y-%m-%D') | |
} | |
#connection with the database | |
client = MongoClient('mongodb://localhost:27017/') | |
#selection by collecion | |
db = client.BlogEhAjudaEu | |
#select use document(table) | |
posts = db.posts | |
print(posts.insert_one(post)) | |
print(posts.find_one()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment