Created
August 28, 2017 03:25
-
-
Save shravan-kuchkula/ad1f666b9952f74eb621c2efcf9e6632 to your computer and use it in GitHub Desktop.
A simple pymongo script to create the people collection
This file contains 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 | |
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