#!/usr/bin/env python import pymongo from pymongo import MongoClient client = MongoClient('archerdb2.ph.ed.ac.uk', 27017) # Change the database to your one. db = client.charaka_db customers = db.customers # A utility function to print the whole customers collection. def CUSTOMERS(): for customer in customers.find(): print customer # Print all the customers (documents) in the "customers" collection print "--- List of customers ---" CUSTOMERS() print #Create new customers and add them to the customers collection more_customers = [{"name": "John Smith", "address": "5 Magnum Road", "DoB": "1984-01-31"}, {"name":"Garry Khan", "address": " 133 Market St", "DoB": "1976-03-20"}] customers.insert(more_customers); print print "-- The list after adding new customers" CUSTOMERS() print #Search for "John Smith" print "--- Searching for John Smith ----" for customer in customers.find({"name":"John Smith"}): print customer #Remove "John Smith" from the customers collections query = {"name": "John Smith"} customers.remove(query) print print "-- The list after removing John Smith" CUSTOMERS() print