Skip to content

Instantly share code, notes, and snippets.

@KalikaKay
Last active July 3, 2016 04:02
Show Gist options
  • Save KalikaKay/cc407ec2025d234434266c218ce2f718 to your computer and use it in GitHub Desktop.
Save KalikaKay/cc407ec2025d234434266c218ce2f718 to your computer and use it in GitHub Desktop.
/* Match for numbers in zip */
db.zips.aggregate([
{$project: { first_char: {$substr : ["$city",0,1]}, population: "$pop" } },
{$group:{ _id: "$first_char", summation: {$sum:"$population"}}},
{$match: { _id: { $in: [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] } } } ,
{$group:{ _id: null, total: {$sum:"$summation"}}}
])
/* I don't want any quizzes */
db.grades.aggregate (
[
{ $unwind:"$scores" },
{ $match: {"scores.type": {$ne: "quiz"}}},
{ $group:
{
_id:
{
class: "$class_id"
} ,
AvgScore:
{
$avg: "$scores.score"
}
}
},
{ $sort: { "AvgScore": 1 } }
],
{ allowDiskUse: true }
)
@KalikaKay
Copy link
Author

Memory all alone in the moonlight ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment