Skip to content

Instantly share code, notes, and snippets.

@rohitbishnoi
Created August 22, 2016 17:27
Show Gist options
  • Save rohitbishnoi/e2d4e7e94bd6aab7f6ade391a2759a65 to your computer and use it in GitHub Desktop.
Save rohitbishnoi/e2d4e7e94bd6aab7f6ade391a2759a65 to your computer and use it in GitHub Desktop.
MongoDB for Developers: Homework 3.1
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