You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MongoDB运行insertMany代码触发SyntaxError错误,寻求解决方法

MongoDB插入文档语法错误解决方法
  • 错误根源:第一条文档的rating字段值写法有误,你写的rating:4,8里用逗号分隔数字,会被MongoDB Shell解析成新的属性分隔符,破坏了键值对的语法结构,进而触发"missing : after property id"错误。小数必须用点号(.)表示,不能用逗号。

修正后的代码:

db.tours.insertMany([
  {name:"The seas explorer",price:497,rating:4.8},
  {name:"The Snow Adventurer", price:997,rating:4.9, difficulty:"easy"}
])
  • 注意事项:所有数值类型的字段(比如价格、评分)都要使用正确的小数格式,用.作为小数点,避免用逗号引发语法混乱。

内容的提问来源于stack exchange,提问作者Abhishek Srinivasan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 10:31:19