ValueError: Too many values to unpack

2024/11/13 9:40:05

Task is to find,sort,and remove the student with 'type': "homework" and with the lowest score using MongoDB. I also tried to use toArray() function,but it gave an error. Now I try to move on in document as a number of counter and to remove the last sorted document with the lowest score.

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 databasedb=connection.studentsgrades = db.gradestry: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()
Answer

collection.find only takes one positional argument and you're giving it two.

Change your calls so that they look like the following: grades.find({"type": "homework", "student_id": i}).

https://en.xdnf.cn/q/119779.html

Related Q&A

Pandas - Create dynamic column(s) from a single columns values

I have JSON data which I am planning after converting it to desired dataframe, will concat with another dataframe. Participant**row 1** [{roles: [{type: director}, {type: founder}, {type: owner}, {type…

How to automatically remove certain preprocessors directives and comments from a C header-file?

Whats a good way to remove all text from a file which lies between /* */ and #if 0 and corresponding #endif? I want to strip these parts from C headers. This is the code I have so far:For line in file…

Get all pairs from elements in sublists

I have a list of sublists. I need all possible pairs between the elements in the sublists. For example, for a list like this: a=[[1,2,3],[4,5],[6]]The result should be: result=[[1,4], [1,5], [1,6], [2,…

Extracting variables from Javascript inside HTML

I need all the lines which contains the text .mp4. The Html file has no tag!My code:import urllib.request import demjson url = (https://myurl) content = urllib.request.urlopen(url).read()<script typ…

Pygame, self is not defined [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Python 3- assigns grades [duplicate]

This question already has answers here:Python 3- Assign grade(2 answers)Closed 8 years ago.• Define a function to prompt the user to enter valid scores until they enter a sentinel value -999. Have …

how to read video data from memory use pyqt5

i have an encrypted video file, i want to decrypt this file into memory and then use this data play video. but qt mediaplayer class is to pass a file name in, i need to have any good way?this is my co…

Pandas apply custom function to DF

I would like to create a brand new data frame by replacing values of a DF using a custom function. I keep getting the following error "ValueError: The truth value of a Series is ambiguous. Use a.e…

Economy Bot Daily Streak

I have a Discord.py economy bot that includes a daily command It gives everyone each day $50, but there is also a streak system. The first time they claim their daily, the bot gives them $50, day 2 is …

Normalise JSON with Python

Prompt me, please, how to normalize this JSON file using Python? This question is related to the previous The current JSON contains: {"total_stats": [{"domain": "domain.com&qu…