Skip to content

Instantly share code, notes, and snippets.

@kenwalger
Created June 12, 2018 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwalger/156baee55dec91ceac1d700c9e4935bf to your computer and use it in GitHub Desktop.
Save kenwalger/156baee55dec91ceac1d700c9e4935bf to your computer and use it in GitHub Desktop.
PyMongo Sample for Advocacy Hub
from pymongo import MongoClient
import datetime
client = MongoClient('localhost', 27017)
db = client['advocacy-hub-db']
collection = db['pyMongo']
post = {"author": "Ken",
"text": "Wow, this is really great!",
"tags": ["mongodb", "python", "pymongo", "gist"],
"date": datetime.datetime.utcnow()
}
posts = db.posts
post_id = posts.insert_one(post).inserted_id
print(post_id)
# Output: 5b2055cd146bde0cbc6fd305
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment