【发布时间】: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