I think you should do the following code to solve the problems
var lowScore = 9999.9; for ( var i=0; i<doc.scores.length; i++ ) { if ( doc.scores[i].type == "homework" && doc.scores[i].score < lowScore ) { lowScore = doc.scores[i].score; } }
and then update your collection using the following query
collection.update({ "_id":doc._id }, { $pull : { "scores" : { $and: [ {"type":"homework"}, { "score":lowScore} ] } } }, { "safe":true }, function( err, result ) { if (err) { console.log(err); } }
for more information you can refer to here
source share