Slide 30
Slide 30 text
SQL
&
MongoDB
db.users.aggregate([
{$match: {
age: {$gte: 16}}},
{$group: {
_id: “$city”,
count: {$sum: 1}}},
{$match: {
count: {$lt: 10000}}},
{$sort: {
adult_count: -1}},
{$project: {
_id: 0,
city: “$_id”,
adult_count: “$count”}}]);
select - $project
where/having - $match
group by - $group
order by - $sort
select city, count(id)
from users
where age >= 16
group by city
having count(id) < 10000
order by 2 desc