-
-
Save skatesham/685d1d357470679b9f2d89cddab751b3 to your computer and use it in GitHub Desktop.
CRUD MongoDB exception
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
| import pymongo | |
| import sys | |
| def main(): | |
| connection = pymongo.MongoClient("mongodb://localhost") | |
| db = connection.m101 | |
| people = db.people | |
| person = {'name': 'Barack Obama', 'role':'President', | |
| 'address':{'address1':'The White House', | |
| 'street': '1600 Pensylvania Avenue', | |
| 'state': 'DC', | |
| 'city': 'Washington'}, | |
| 'interests':['government', 'basketball', 'the middle east']} | |
| people.insert(person) | |
| person = people.find_one({'name': 'Barack Obama'}) | |
| print person | |
| try: | |
| people.insert(person) | |
| except: | |
| print 'insertion failed', sys.exc_info()[0] | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment