MongoDB 中的大量插入
对于大量插入,请使用 MongoDB 中的 insertMany() 概念。insertMany() 将多个文档插入集合中。
让我们创建一个具有文档的集合−
> db.demo729.insertMany( [ ... { BankName:"HDFC Bank",cardType:"Credit","CustomerName":[{Name:"Chris",Age:25}]}, ... { BankName:"ICICI Bank",cardType:"Debit","CustomerName":[{Name:"Bob",Age:22}]}, ... { BankName:"Kotak Bank",cardType:"Debit","CustomerName":[{Name:"David",Age:23}]} ... ] ); { "acknowledged" : true, "insertedIds" : [ ObjectId("5eac510d56e85a39df5f6333"), ObjectId("5eac510d56e85a39df5f6334"), ObjectId("5eac510d56e85a39df5f6335") ] }
借助 find() 方法显示集合中的所有文档−
> db.demo729.find().pretty();
这将生成以下输出 −
{ "_id" : ObjectId("5eac510d56e85a39df5f6333"), "BankName" : "HDFC Bank", "cardType" : "Credit", "CustomerName" : [ { "Name" : "Chris", "Age" : 25 } ] } { "_id" : ObjectId("5eac510d56e85a39df5f6334"), "BankName" : "ICICI Bank", "cardType" : "Debit", "CustomerName" : [ { "Name" : "Bob", "Age" : 22 } ] } { "_id" : ObjectId("5eac510d56e85a39df5f6335"), "BankName" : "Kotak Bank", "cardType" : "Debit", "CustomerName" : [ { "Name" : "David", "Age" : 23 } ] }
广告