【问题标题】:SyntaxError: missing : after property id - MongoDB语法错误:缺少:属性 id 之后 - MongoDB
【发布时间】:2019-06-02 08:28:36
【问题描述】:

我有以下收藏:

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

要求是找到每个部门的工资正好是50000的员工人数。

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

它抛出错误消息:missing : after property id.但我没有看到语法有任何问题。

【问题讨论】:

    标签: mongodb mongodb-query


    【解决方案1】:

    $sum 后面有一个逗号,而 MongoDB 需要一个冒号,试试:

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

    【讨论】:

      猜你喜欢
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      • 2011-04-13
      • 1970-01-01
      • 2013-01-23
      相关资源
      最近更新 更多