-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_student_data.py
More file actions
49 lines (31 loc) · 1002 Bytes
/
remove_student_data.py
File metadata and controls
49 lines (31 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Andrew Erlichson
# MongoDB, Inc.
# M101P - Copyright 2015, All Rights Reserved
import pymongo
import datetime
import sys
# establish a connection to the database
connection = pymongo.MongoClient("mongodb://localhost")
# removes one student
def remove_student(student_id):
# get a handle to the school database
db=connection.school
scores = db.scores
try:
result = scores.delete_many({'student_id':student_id})
print "num removed: ", result.deleted_count
except Exception as e:
print "Exception: ", type(e), e
def find_student_data(student_id):
# get a handle to the school database
db=connection.school
scores = db.scores
print "Searching for student data for student with id = ", student_id
try:
docs = scores.find({'student_id':student_id})
for doc in docs:
print doc
except Exception as e:
print "Exception: ", type(e), e
remove_student(1)
find_student_data(1)