Skip to content

Instantly share code, notes, and snippets.

@tim-hub
Created February 20, 2017 08:11
Show Gist options
  • Save tim-hub/fe815745e130f6d11805cfeca329cd48 to your computer and use it in GitHub Desktop.
Save tim-hub/fe815745e130f6d11805cfeca329cd48 to your computer and use it in GitHub Desktop.
import pymongo
import sys
c = pymongo.MongoClient(host=["mongodb://localhost:27017",
"mongodb://localhost:27018",
"mongodb://localhost:27019"],
replicaSet="m101",
w=1,
j=True)
db = c.m101
people = db.people
try:
print "inserting"
people.insert_one({"name":"Andrew Erlichson", "favorite_color":"blue"})
print "inserting"
people.insert_one({"name":"Richard Krueter", "favorite_color":"red"})
print "inserting"
people.insert_one({"name":"Dwight Merriman", "favorite_color":"green"})
except Exception as e:
print "Unexpected error:", type(e), e
print "completed the inserts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment