-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing_insert_one.py
More file actions
34 lines (23 loc) · 854 Bytes
/
using_insert_one.py
File metadata and controls
34 lines (23 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import pymongo
# establish a connection to the database
connection = pymongo.MongoClient("mongodb://localhost")
def insert_two():
# get a handle to the school database
db = connection.school
people = db.people
print "insert, reporting for duty"
richard = {"name": "Richard Kreuter", "company": "MongoDB",
"interests": ['horses', 'skydiving', 'fencing']}
andrew = {"_id": "erlichson", "name": "Andrew Erlichson",
"company": "MongoDB", "interests": ['running', 'cycling',
'photography']}
try:
people.insert_one(richard)
people.insert_one(andrew)
except Exception as e:
print "Unexpected error:", type(e), e
print(richard)
print(andrew)
if __name__ == '__main__':
insert_two()