Skip to content

Instantly share code, notes, and snippets.

@shravan-kuchkula
Created August 28, 2017 03:25
Show Gist options
  • Save shravan-kuchkula/ad1f666b9952f74eb621c2efcf9e6632 to your computer and use it in GitHub Desktop.
Save shravan-kuchkula/ad1f666b9952f74eb621c2efcf9e6632 to your computer and use it in GitHub Desktop.
A simple pymongo script to create the people collection
import pymongo
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.school
people = db.people
people.drop()
def insert(peopleList):
print("insert reporting for duty")
for item in peopleList:
people.insert_one(item)
def main():
peopleList = [
{"name": "Smith", "age": 30, "profession": "hacker"},
{"name": "Jones", "age": 35, "profession": "baker"},
{"name": "Alice"},
{"name": "Bob"},
{"name": "Charlie"},
{"name": "Dave"},
{"name": "Edgar"},
{"name": "Fred"},
{"name": 42}
]
insert(peopleList)
for item in people.find():
print(item)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment