Created
March 20, 2014 00:40
-
-
Save lucasmcastro/9654941 to your computer and use it in GitHub Desktop.
mongo + pymongo + mongolab
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 pymongo import MongoClient | |
>>> import datetime | |
post = {"author": "Mike","text": "My first blog post!","tags": ["mongodb", "python", "pymongo"], "date": datetime.datetime.utcnow()} | |
>>> uri = "mongodb://pyladies:[email protected]: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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, you made my week