Skip to content

Instantly share code, notes, and snippets.

@tiagovizoto
Created October 26, 2016 20:28
Show Gist options
  • Save tiagovizoto/8c0ad3cde83df8083723309e4f7f5ee6 to your computer and use it in GitHub Desktop.
Save tiagovizoto/8c0ad3cde83df8083723309e4f7f5ee6 to your computer and use it in GitHub Desktop.
Example MongoDB with Python
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