-2
任务是使用MongoDB查找,排序和删除学生'type':“家庭作业”和最低分数。我也尝试使用toArray()
函数,但它给出了一个错误。现在我尝试在文档中继续前进,并删除最低分数的最后一个排序文档。ValueError:<太多解压值>
import pymongo
import sys
#establish a connection to the database
connection = pymongo.MongoClient("mongodb://localhost")
def delete_lowest_doc():
#get a handle to the students database
db=connection.students
grades = db.grades
try:
for i in range(0,grades.find().count()):
docs_1 = grades.find({'type':"homework", 'student_id':i}).sort(['score',-1])
counter_1 = grades.find({'type':"homework",'student_id':i})
counter_2 = counter_1.sort(['score',-1]).count()
while (counter_2>0):
doc = docs_1.next();
counter_2=counter_2-1;
grades.remove(doc)
except Exception as e:
print ("Unexpected error:", type(e), e)
delete_lowest_doc()
我做了一个改变。再次得到相同的错误。 – 2015-03-30 21:55:08