0

データベースにこのドキュメントがあります

{ "_id" : { "$oid" : "50906d7fa3c412bb040eb579"} , "student_id" : 0 , "type" : "homework" , "score" : 14.8504576811645}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57a"} , "student_id" : 0 , "type" : "homework" , "score" : 63.98402553675503}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57d"} , "student_id" : 1 , "type" : "homework" , "score" : 21.33260810416115}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57e"} , "student_id" : 1 , "type" : "homework" , "score" : 44.31667452616328}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb581"} , "student_id" : 2 , "type" : "homework" , "score" : 60.9750047106029}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb582"} , "student_id" : 2 , "type" : "homework" , "score" : 97.75889721343528}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb585"} , "student_id" : 3 , "type" : "homework" , "score" : 50.81577033538815}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb586"} , "student_id" : 3 , "type" : "homework" , "score" : 92.71871597581605}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb589"} , "student_id" : 4 , "type" : "homework" , "score" : 5.244452510818443}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb58a"} , "student_id" : 4 , "type" : "homework" , "score" : 28.656451042441}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb58d"} , "student_id" : 5 , "type" : "homework" , "score" : 23.29430953857654}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb58e"} , "student_id" : 5 , "type" : "homework" , "score" : 41.21853026961924}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb591"} , "student_id" : 6 , "type" : "homework" , "score" : 81.23822046161325}
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb592"} , "student_id" : 6 , "type" : "homework" , "score" : 89.72700715074382}

ここでstudent_idは各生徒を表し、各生徒は合計 100 点に相当する 2 つの宿題を作成したため、両方の宿題の点数を比較し、その生徒の低い点数を削除したいと考えています。

ここに私のコードがあります

`try {
Mongo mongo = new Mongo("localhost");

        DB db = mongo.getDB("students");   


        DBCollection collection = db.getCollection("grades");  

        DBCursor cursor = collection.find();  
        BasicDBObject query = new BasicDBObject();  
        query.put("type", "homework");  
        cursor = collection.find(query).sort(new BasicDBObject("student_id", 1));  
        System.out.println(cursor.count());  


        try{  
            while(cursor.hasNext()){  

                System.out.println(cursor.next());  

            }  
        }finally{  
            cursor.close();  
        }  

    } catch (UnknownHostException e) {  

        e.printStackTrace();  
    }`  
4

0 に答える 0