Sboh
Sboh

Reputation: 87

MongoDB error: uncaught exception: SyntaxError: missing ] after element list :

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 } } }] )

Upvotes: 0

Views: 112

Answers (1)

Phat Dang
Phat Dang

Reputation: 517

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 } }
  }
])

Upvotes: 1

Related Questions