Created
August 22, 2016 17:27
-
-
Save rohitbishnoi/e2d4e7e94bd6aab7f6ade391a2759a65 to your computer and use it in GitHub Desktop.
MongoDB for Developers: Homework 3.1
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
from pymongo import MongoClient | |
def remove_lowest_score(student): | |
homework_scores = filter(lambda x: x['type'] == "homework", student['scores']) | |
all_homework_scores = map(lambda x: x['score'], homework_scores) | |
min_homework_score = min(all_homework_scores) | |
all_scores = filter(lambda x: not(x['type'] == "homework" and x['score'] == min_homework_score), student['scores']) | |
db.students.update_one({"_id": student["_id"]}, {"$set": {"scores" : all_scores}}) | |
client = MongoClient() | |
db = client.school | |
cursor = db.students.find() | |
for document in cursor: | |
remove_lowest_score(document) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment