Answer the question
In order to leave comments, you need to log in
How to remove a field in MongoDB from the command line?
Hello, the task ahead is:
There are 800 fields with marks
> db.grades.find().count()
800
> db.grades.find()
{ "_id" : ObjectId("50906d7fa3c412bb040eb57a"), "student_id" : 0, "type" : "homework", "score" : 63.98402553675503 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb579"), "student_id" : 0, "type" : "homework", "score" : 14.8504576811645 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb578"), "student_id" : 0, "type" : "quiz", "score" : 31.95004496742112 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb577"), "student_id" : 0, "type" : "exam", "score" : 54.6535436362647 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57b"), "student_id" : 1, "type" : "exam", "score" : 74.20010837299897 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57c"), "student_id" : 1, "type" : "quiz", "score" : 96.76851542258362 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57e"), "student_id" : 1, "type" : "homework", "score" : 44.31667452616328 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57d"), "student_id" : 1, "type" : "homework", "score" : 21.33260810416115 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57f"), "student_id" : 2, "type" : "exam", "score" : 19.88180838833524 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb582"), "student_id" : 2, "type" : "homework", "score" : 97.75889721343528 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb581"), "student_id" : 2, "type" : "homework", "score" : 60.9750047106029 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb584"), "student_id" : 3, "type" : "quiz", "score" : 82.59760859306996 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb583"), "student_id" : 3, "type" : "exam", "score" : 92.6244233936537 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb585"), "student_id" : 3, "type" : "homework", "score" : 50.81577033538815 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb586"), "student_id" : 3, "type" : "homework", "score" : 92.71871597581605 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb580"), "student_id" : 2, "type" : "quiz", "score" : 1.528220212203968 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb58a"), "student_id" : 4, "type" : "homework", "score" : 28.656451042441 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb58b"), "student_id" : 5, "type" : "exam", "score" : 49.41260067227861 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb587"), "student_id" : 4, "type" : "exam", "score" : 87.89071881934647 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb588"), "student_id" : 4, "type" : "quiz", "score" : 27.29006335059361 }
Type "it" for more
> db.grades.find({type:'homework'}).count()
400
> db.grades.aggregate([{'$match':{type:'homework'}}, {'$group':{'_id':'$student_id', 'score':{$min:'$score'}}}, {'$sort':{_id:1}}])
{ "_id" : 0, "score" : 14.8504576811645 }
{ "_id" : 1, "score" : 21.33260810416115 }
{ "_id" : 2, "score" : 60.9750047106029 }
{ "_id" : 3, "score" : 50.81577033538815 }
{ "_id" : 4, "score" : 5.244452510818443 }
{ "_id" : 5, "score" : 23.29430953857654 }
{ "_id" : 6, "score" : 81.23822046161325 }
{ "_id" : 7, "score" : 63.35102050393443 }
{ "_id" : 8, "score" : 66.42784200049636 }
{ "_id" : 9, "score" : 16.60130789148128 }
{ "_id" : 10, "score" : 6.094174990746648 }
{ "_id" : 11, "score" : 27.42742674795513 }
{ "_id" : 12, "score" : 51.69676516705788 }
{ "_id" : 13, "score" : 0.4838914493376478 }
{ "_id" : 14, "score" : 63.69676709320795 }
{ "_id" : 15, "score" : 7.475648374118382 }
{ "_id" : 16, "score" : 12.8489522283682 }
{ "_id" : 17, "score" : 32.33461505658801 }
{ "_id" : 18, "score" : 16.31570053358192 }
{ "_id" : 19, "score" : 19.50958720409689 }
Type "it" for more
> db.grades.find()
{ "_id" : ObjectId("50906d7fa3c412bb040eb57a"), "student_id" : 0, "type" : "homework", "score" : 63.98402553675503 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb578"), "student_id" : 0, "type" : "quiz", "score" : 31.95004496742112 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb577"), "student_id" : 0, "type" : "exam", "score" : 54.6535436362647 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57b"), "student_id" : 1, "type" : "exam", "score" : 74.20010837299897 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57c"), "student_id" : 1, "type" : "quiz", "score" : 96.76851542258362 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57e"), "student_id" : 1, "type" : "homework", "score" : 44.31667452616328 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb57f"), "student_id" : 2, "type" : "exam", "score" : 19.88180838833524 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb582"), "student_id" : 2, "type" : "homework", "score" : 97.75889721343528 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb584"), "student_id" : 3, "type" : "quiz", "score" : 82.59760859306996 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb583"), "student_id" : 3, "type" : "exam", "score" : 92.6244233936537 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb586"), "student_id" : 3, "type" : "homework", "score" : 92.71871597581605 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb580"), "student_id" : 2, "type" : "quiz", "score" : 1.528220212203968 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb58b"), "student_id" : 5, "type" : "exam", "score" : 49.41260067227861 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb587"), "student_id" : 4, "type" : "exam", "score" : 87.89071881934647 }
{ "_id" : ObjectId("50906d7fa3c412bb040eb588"), "student_id" : 4, "type" : "quiz", "score" : 27.29006335059361 }
Type "it" for more
Answer the question
In order to leave comments, you need to log in
Read https://docs.mongodb.com/v3.2/reference/method/db....
Read about $unset
Read about multi: true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question