对于多个插入,请在MongoDB中使用insert()。让我们用文档创建一个集合-
> db.demo689.insert([ ... {ClientName:"Chris","ClientAge":34,"ClientCountryName":"US"}, ... {ClientName:"David","ClientAge":28,"ClientCountryName":"UK"}, ... {ClientName:"Bob","ClientAge":39,"ClientCountryName":"AUS"}, ... ]); BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 3, "nUpserted" : 0, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "upserted" : [ ] })
在find()方法的帮助下显示集合中的所有文档-
> db.demo689.find();
这将产生以下输出-
{ "_id" : ObjectId("5ea580dfa7e81adc6a0b3967"), "ClientName" : "Chris", "ClientAge" : 34, "ClientCountryName" : "US" } { "_id" : ObjectId("5ea580dfa7e81adc6a0b3968"), "ClientName" : "David", "ClientAge" : 28, "ClientCountryName" : "UK" } { "_id" : ObjectId("5ea580dfa7e81adc6a0b3969"), "ClientName" : "Bob", "ClientAge" : 39, "ClientCountryName" : "AUS" }