Nandy
Nandy

Reputation: 696

SyntaxError: missing : after property id - MongoDB

I have the collection below:

    db.emp.insertMany(
    [
    {"name":"Nandhi","dept":"BPO","Salary":50000},
    {"name":"Raj","dept":"IT","Salary":5000},
    {"name":"Dave","dept":"IT","Salary":50000},
    {"name":"Pand","dept":"IT","Salary":50000},
    ]
    )

The requirement is to find the number of employees at each department whose salary is exactly 50000.

    db.emp.aggregate([
    {$match:{"Salary":50000}},
    {$group:{_id:{dept:"$dept"},cnt:{$sum,1}}}
    ])

Its throwing the error message: missing : after property id. But i am not seeing any issue with the syntax.

Upvotes: 0

Views: 1954

Answers (1)

mickl
mickl

Reputation: 49945

You have a comma after $sum while MongoDB expects a colon there, try:

db.emp.aggregate([
    {$match:{"Salary":50000}},
    {$group:{_id:{dept:"$dept"},cnt:{$sum:1}}}
])

Upvotes: 2

Related Questions