Created
September 8, 2015 03:44
-
-
Save anapaulagomes/25a147c273af7ad0c4e7 to your computer and use it in GitHub Desktop.
Calcula a média de um atributo de um vetor excluindo um atributo desejado - MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.grades.aggregate([ | |
{ $unwind : "$scores" }, | |
{ $project : { type : "$scores.type" , score: "$scores.score", class_id: "$class_id"} }, | |
{ $match : { type : { $ne : "atributo_que_quer_excluir" } } }, | |
{ $group: | |
{ | |
_id: '$class_id', | |
media: {$avg: '$score'} | |
} | |
}, | |
{ $sort: {media:-1} } | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment