Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays MongoDB。属性名称中缺少“]_Arrays_Mongodb_Collections_Insert_Database - Fatal编程技术网

Arrays MongoDB。属性名称中缺少“]

Arrays MongoDB。属性名称中缺少“],arrays,mongodb,collections,insert,database,Arrays,Mongodb,Collections,Insert,Database,您好,我有一本藏书,我想在其中插入一系列文档: > 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:2

您好,我有一本藏书,我想在其中插入一系列文档:

> 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},{a:3.23},{b:'abc'},
{c:new Date()},{d:[1,2,3]}, {f:1} ])

它将是
db.book.insert([{“x”:null},{“y”:true}])
。您将方括号
[]
“放在”花括号
{}
内。它的意思是“外面”成为“名单”,你是对的!非常感谢。