【问题标题】:MongoDB. Missing ] in property nameMongoDB。属性名称中缺少 ]
【发布时间】:2016-03-05 22:00:02
【问题描述】:

您好,我有一个图书收藏,我想在其中插入一组文档:

> db.book.insert({[ {x:null},{y:true},{a:3.23},{b:'abc'},
  {c:new Date()},{d:[1,2,3]}, {f:1} ]})

它给了我这个错误:

2016-03-06T00:53:58.893+0300 E QUERY    
[thread1] **SyntaxError: missing ] in computed property name @(shell):1:27**

看不到丢失的']',我的错是什么?

我想同时添加 7 个文档。

我需要将所有文档包含在一个数组中,对吗? .insert({[ ... ]})

如您所见,文档 'd' 也是一个数组。

【问题讨论】:

  • 应该是db.book.insert([{ "x": null },{ "y": true }])。您将方括号[] 放置在大括号{} 的“内部”。它意味着在“外部”成为“列表”
  • 你是对的!谢谢

标签: arrays mongodb collections insert database


【解决方案1】:

通过去掉'()'中的'{}'解决:

最终结果:

db.book.insert([ {x:null},{y:true},{a:3.23},{b:'abc'},
{c:new Date()},{d:[1,2,3]}, {f:1} ])

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    相关资源
    最近更新 更多