Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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
Json 是否可以通过单个insert()调用向MongoDB集合插入多个文档?_Json_Mongodb_Insert_Database - Fatal编程技术网

Json 是否可以通过单个insert()调用向MongoDB集合插入多个文档?

Json 是否可以通过单个insert()调用向MongoDB集合插入多个文档?,json,mongodb,insert,database,Json,Mongodb,Insert,Database,我在MongoDB的交互shell中定义了两个变量: a = {"letter": "a"} b = {"letter": "b"} 现在,我想将它们添加到数据库stackoverflow中的集合newColl: use stackoverflow db.newColl.insert(a) db.newColl.insert(b) 我想知道是否可以一次性插入两个文档,例如: // Not working! db.newColl.insert(a, b) 如果将两个文档放入一个数组中,它将起

我在MongoDB的交互shell中定义了两个变量:

a = {"letter": "a"}
b = {"letter": "b"}
现在,我想将它们添加到数据库
stackoverflow
中的集合
newColl

use stackoverflow
db.newColl.insert(a)
db.newColl.insert(b)
我想知道是否可以一次性插入两个文档,例如:

// Not working!
db.newColl.insert(a, b)

如果将两个文档放入一个数组中,它将起作用:

db.newColl.insert([a,b])
只需使用数组:

db.collection.isert([doc1:adsadad, doc2:asdad, etc, etc])