I'm new to mongodb database and I find it complecated. I have books table, and I want to count all books published after 2009, and I'm getting this error message:
uncaught exception: SyntaxError: missing ] after element list
Here is my query:
db.books.aggregate( [ {$match: {"books.year":{$gt: 2009}}},
{ $group: { _id: null, count: { $sum: 1 } } }] )
CodePudding user response:
I think you got some syntax error in your query. To modify, it should be:
db.books.aggregate( [
{
"$match": {
"year": {"$gt": 2009}
}
},
{
"$group": {
"_id": <field that you want to group by, for example "$genre" or "$year">,
"count": { "$sum": 1 } }
}
])