javascript – mongodb出错.在属性列表后缺少“}”

使用以下代码我收到此错误:

SyntaxError: missing } after property list <shell>:3

有谁知道我做错了什么?花括号看起来很平衡,所以我想知道我是否在其他地方犯了错误.

db.test.save(
{
     "name":"John Doe"
     "attribute":"false"
     "num1":99
     "num2":85
     "num3"{
            "n1":11
            "n2":9
            "n3":8
            "n4":9
     }
     "num4"{
            "m1":15
            "m2":6
            "m3":5
            "m4":12
     }
}
)

解决方法:

缺少冒号.

 "num3":{
       ^

 "num4":{
       ^

还有逗号.

 "name":"John Doe",
                  ^
 "attribute":"false",
                    ^
 "num3"{
        "n1":11, //commas to separate these object properties too
        "n2":9,
        "n3":8,
        "n4":9
 },
  ^
 //etc

这应该执行:

{
     "name":"John Doe",
     "attribute":"false",
     "num1":99,
     "num2":85,
     "num3":{
            "n1":11,
            "n2":9,
            "n3":8,
            "n4":9
     },
     "num4":{
            "m1":15,
            "m2":6,
            "m3":5,
            "m4":12
     }
}

MongoDB update docs中还有一些有效文档的例子.

上一篇:mongodb查询案例,golang库mgo案例


下一篇:c# – 使用流通过Json.NET创建BSON字节数组(用于文件格式)