Created
October 23, 2015 19:02
-
-
Save sherlockholmes/5064d4197d03b0732cd6 to your computer and use it in GitHub Desktop.
HOMEWORK 2 - WEEK 2 - M101P
This file contains hidden or 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 | |
| import datetime | |
| import sys | |
| # establish a connection to the database | |
| connection = pymongo.MongoClient("mongodb://localhost") | |
| def find_student_data_and_delete_min(student_id): | |
| # get a handle to the school database | |
| db=connection.students | |
| grades = db.grades | |
| query = {'student_id':student_id, 'type':'homework'} | |
| print "Searching for student data for student with id = ", student_id | |
| try: | |
| cursor = grades.find(query) | |
| cursor = cursor.sort('score', pymongo.ASCENDING) | |
| cursor = cursor.limit(1) | |
| for doc in cursor: | |
| grades.delete_many(doc) | |
| except Exception as e: | |
| print "Exception: ", type(e), e | |
| i = 0 | |
| while (i < 200): | |
| find_student_data_and_delete_min(i) | |
| i = i + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment