Follow the Mongdb authoritative guide when using version 3.4. 1 version of MongoDB, which uses the Batchinsert function to BULK Insert the students collection
Db.students.batchInsert ([{"ClassID": 1, "age": +, "name": "Kobe"}, {"ClassID": 1, "Age": Max, "name" : "Nash"}, {"ClassID": 2, "age": +, "name": "James"}, {"ClassID": 2, "age": +, "name": "Wade"}, {"ClassID ": 2," age ": +," name ":" Bosh "}, {" ClassID ": 2," age ": +," name ":" Allen "}, {" ClassID ": 1," age ": +," n Ame ":" Howard "}, {" ClassID ": 1," age ": +," name ":" Paul "}, {" ClassID ": 2," age ": $," name ":" Shane "}]);
The insert failed with the following error:
2018 - Geneva -26t21:40.382+0800[main]is notfunction : @ (Shell):1:1
Reason: The sample Batchinsert in the book is run according to Version:2.4.0, which has been deprecated by this version
Workaround: Bulk Insert the students collection using insert implementation directly
Db.students. Insert ([{"ClassID": 1, "age": +, "name": "Kobe"}, {"ClassID": 1, "Age": Max, "name": "Nash"}, {"ClassID" : 2, "age": +, "name": "James"}, {"ClassID": 2, "age": +, "name": "Wade"}, {"ClassID": 2, "Age": "Nam E ":" Bosh "}, {" ClassID ": 2," age ": +," name ":" Allen "}, {" ClassID ": 1," age ": +," name ":" Howard "}, { "ClassID": 1, "age": +, "name": "Paul"}, {"ClassID": 2, "age": $, "name": "Shane"}]);
db.students.find ()
The console output is as follows and the insert succeeds
//Command #1://Execution time:0.0s//Result:Bulkwriteresult ({"Writeerrors" : [ ], "Writeconcernerrors" : [ ], "Ninserted": 9, "Nupserted": 0, "Nmatched": 0, "Nmodified": 0, "Nremoved": 0, "Upserted" : [ ]})//Command #2://Db.students.find ()//Execution time:0.0s//Result:{"_id": ObjectId ("5a940a3f379afc334959cacc"), "ClassID": 1, "age": +, "name": "Kobe" }{ "_id": ObjectId ("5A940A3F379AFC334959CACD"), "ClassID": 1, "age": All, "name": "Nash" }{ "_id": ObjectId ("5a940a3f379afc334959cace"), "ClassID": 2, "age": "Name": "James" }{ "_id": ObjectId ("5A940A3F379AFC334959CACF"), "ClassID": 2, "age": +, "name": "Wade" }{ "_id": ObjectId ("5a940a3f379afc334959cad0"), "ClassID": 2, "age": +, "name": "Bosh" }{ "_id": ObjectId ("5a940a3f379afc334959cad1"), "ClassID": 2, "age": +, "name": "Allen" }{ "_id": ObjectId ("5a940a3f379afc334959cad2"), "ClassID": 1, "age": +, "name": "Howard" }{ "_id": ObjectId ("5a940a3f379afc334959cad3"), "ClassID": 1, "Age": "Name": "Paul" }{ "_id": ObjectId ("5a940a3f379afc334959cad4"), "ClassID": 2, "age": $, "name": "Shane"}
Db.students.batchInsert is not a function: @ (Shell): 1:1