在MongoDB中执行批量插入?
要在MongoDB中批量插入,请使用initializeUnorderedBulkOp()。让我们创建一个包含文档的集合-
> var bulkInsertDoc = db.demo663.initializeUnorderedBulkOp();
> bulkInsertDoc.insert( { Name: "John",CountryName:"US"} );
> bulkInsertDoc.insert( { Name: "Chris",CountryName:"UK"} );
> bulkInsertDoc.insert( { Name: "David",CountryName:"AUS"} );
> bulkInsertDoc.execute();
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 3,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})在find()方法的帮助下显示集合中的所有文档-
> db.demo663.find();
这将产生以下输出-
{ "_id" : ObjectId("5ea1b41424113ea5458c7d05"), "Name" : "John", "CountryName" : "US" }
{ "_id" : ObjectId("5ea1b41424113ea5458c7d06"), "Name" : "Chris", "CountryName" : "UK" }
{ "_id" : ObjectId("5ea1b41424113ea5458c7d07"), "Name" : "David", "CountryName" : "AUS" }热门推荐
10 广东新居入伙简短祝福语
11 致姐姐生日祝福语简短
12 简短新婚铺被子祝福语
13 庆祝国家的祝福语简短
14 开业经典祝福语简短
15 新年祝福语大全简短老师
16 舅舅大婚文案祝福语简短
17 哥哥结婚的祝福语简短
18 侄儿生日祝福语简短独特