Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import pymongo
- from pymongo import Connection
- from pymongo.errors import ConnectionFailure
- from datetime import datetime
- def main():
- try:
- c = Connection(host="localhost",port=27017)
- except ConnectionFailure as e:
- sys.stderr.write("Could no connect to MongoDB: %s" % e)
- sys.exit(1)
- dbh = c["students"]
- assert dbh.connection == c
- users = dbh.grades.find({'type':'homework'}).sort([['student_id',pymongo.ASCENDING],['score',pymongo.ASCENDING]])
- student_id = -1
- for student in users:
- if student_id != student['student_id']:
- student_id = student['student_id']
- dbh.grades.remove({'_id': student['_id']})
- if __name__=="__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement