Skip to content

Instantly share code, notes, and snippets.

@lucasmcastro
Created March 20, 2014 00:40
Show Gist options
  • Save lucasmcastro/9654941 to your computer and use it in GitHub Desktop.
Save lucasmcastro/9654941 to your computer and use it in GitHub Desktop.
mongo + pymongo + mongolab
>>> from pymongo import MongoClient
>>> import datetime
post = {"author": "Mike","text": "My first blog post!","tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow()}
>>> uri = "mongodb://pyladies:pyladies@dbh16.mongolab.com:27167/series4ladies"
>>> client = MongoClient(uri)
>>> client
MongoClient('dbh16.mongolab.com', 27167)
>>> client.series4ladies
Database(MongoClient('dbh16.mongolab.com', 27167), u'series4ladies')
>>> db = client.series4ladies
>>> posts = db.posts
>>> posts
Collection(Database(MongoClient('dbh16.mongolab.com', 27167), u'series4ladies'), u'posts')
>>> post_id = posts.insert(post)
>>> post_id
ObjectId('532a38550bb4a72d677943f0')
@qilin000
Copy link

Thanks, you made my week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment