Reputation: 1
I have the following T-SQL query :
SELECT year, COUNT(*) FROM publis
WHERE publisher LIKE '%Springer%'
I made this query :
db.publis.aggregate([{"$group" : {_id:"$year", count:{$sum:1}}}])
How can I include the WHERE condition ?
Upvotes: 1
Views: 98
Reputation: 22276
The equivalent of SQL WHERE
is the $match aggregation stage, so you would rewrite you query like so:
db.publis.aggregate([
{
$match: {
publisher: /Springer/,
},
},
{
$group: {
_id: '$year',
count: { $sum: 1 },
},
},
]);
Upvotes: 1