Db.students.batchInsert is not a function: @ (Shell): 1:1

Source: Internet
Author: User
Tags bulk insert

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.