按照《mongdb权威指南》当使用version 3.4.1版本的mongodb,其中使用batchInsert函数进行对students集合进行批量插入

db.students.batchInsert([{"classid" : 1, "age" : 20, "name" : "kobe"},
{"classid" : 1, "age" : 23, "name" : "nash"},
{"classid" : 2, "age" : 18, "name" : "james"},
{"classid" : 2, "age" : 19, "name" : "wade"},
{"classid" : 2, "age" : 19, "name" : "bosh"},
{"classid" : 2, "age" : 25, "name" : "allen"},
{"classid" : 1, "age" : 19, "name" : "howard"},
{"classid" : 1, "age" : 22, "name" : "paul" },
{"classid" : 2, "age" : 24, "name" : "shane"}]);

插入失败,报如下错误:

2018-02-26T21:08:40.382+0800 E QUERY [main] TypeError: db.students.batchInsert is not a function :@(shell):1:1

原因:书中示例batchInsert是按照version:2.4.0运行的,到本版本已经废弃该方法

解决方法:直接使用insert实现对students集合批量插入

db.students.insert([{"classid" : 1, "age" : 20, "name" : "kobe"},
{"classid" : 1, "age" : 23, "name" : "nash"},
{"classid" : 2, "age" : 18, "name" : "james"},
{"classid" : 2, "age" : 19, "name" : "wade"},
{"classid" : 2, "age" : 19, "name" : "bosh"},
{"classid" : 2, "age" : 25, "name" : "allen"},
{"classid" : 1, "age" : 19, "name" : "howard"},
{"classid" : 1, "age" : 22, "name" : "paul" },
{"classid" : 2, "age" : 24, "name" : "shane"}]); db.students.find()

控制台输出如下,插入成功

// 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" : 20, "name" : "kobe" }
{ "_id" : ObjectId("5a940a3f379afc334959cacd"), "classid" : 1, "age" : 23, "name" : "nash" }
{ "_id" : ObjectId("5a940a3f379afc334959cace"), "classid" : 2, "age" : 18, "name" : "james" }
{ "_id" : ObjectId("5a940a3f379afc334959cacf"), "classid" : 2, "age" : 19, "name" : "wade" }
{ "_id" : ObjectId("5a940a3f379afc334959cad0"), "classid" : 2, "age" : 19, "name" : "bosh" }
{ "_id" : ObjectId("5a940a3f379afc334959cad1"), "classid" : 2, "age" : 25, "name" : "allen" }
{ "_id" : ObjectId("5a940a3f379afc334959cad2"), "classid" : 1, "age" : 19, "name" : "howard" }
{ "_id" : ObjectId("5a940a3f379afc334959cad3"), "classid" : 1, "age" : 22, "name" : "paul" }
{ "_id" : ObjectId("5a940a3f379afc334959cad4"), "classid" : 2, "age" : 24, "name" : "shane" }
												

db.students.batchInsert is not a function :@(shell):1:1的更多相关文章

  1. TypeError: db.addUser is not a function : @(shell):1:1 ——mongoDB创建新用户名密码的方法

    不多说,旧版本使用 db.addUser("root","root") 新版本使用这句会出现这个错误提示 TypeError: db.addUser is no ...

  2. mongo数据库基本查询语句

    D:\MongoDB\Server\3.4\bin>mongo MongoDB shell version v3.-g83c3022fe4 connecting to: mongodb://12 ...

  3. MongoDB之二基础入门(安装启动)

    mongodb中有三元素:数据库,集合,文档,其中“集合” 就是对应关系数据库中的“表”,“文档”对应“行”. 一. 下载 上MongoDB官网 ,我们发现有32bit和64bit,这个就要看你系统了 ...

  4. MongoDB之二基础入门(window/linux安装启动)

    mongodb中有三元素:数据库,集合,文档,其中“集合”就是对应关系数据库中的“表”,“文档”对应“行”. 一window安装与启动 一. 下载 上MongoDB官网 ,下载页面:https://w ...

  5. mongoDB关系型数据库的对比

    一.基本操作 1.mongoDB和关系型数据库对比 对比项 mongoDB mysql oracle 表 集合list 二维表 表的一行数据 文档document 一条记录 表字段 键key 字段fi ...

  6. Mongodb DB shell数据操作

    shell命令操作语法和JavaScript很类似,其实控制台底层的查询语句都是用JavaScript脚本完成操作的. Ø 数据库 1.Help查看命令提示 help db.help(); db.yo ...

  7. node.js连接MongoDB数据库,db.collection is not a function完美解决

    解决方法一. mongodb数据库版本回退: 这个错误是出在mongodb的库中,在nodejs里的写法和命令行中的写法不一样,3.0的api已经更新和以前的版本不不一样,我们在npm中没指定版本号的 ...

  8. 快速掌握mongoDB(一)——mongoDB安装部署和常用shell命令

    1.mongoDB简介 mongoDB 是由C++语言编写的,是一种分布式的面向文档存储的开源nosql数据库.nosql是Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统 ...

  9. mongoDB(一)——mongoDB安装部署和常用shell命令

    1.mongoDB简介 mongoDB 是由C++语言编写的,是一种分布式的面向文档存储的开源nosql数据库.nosql是Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统 ...

随机推荐

  1. 在pcDuino上使用蓝牙耳机玩转音乐

    1.资源 pcDuino板子一个.HDMI to VGA线一条.电源线一条.USB hub一个.显示器.鼠标.键盘.蓝牙适配器.蓝牙耳机. 2.资源已经到位,让我们开始吧 1.在ubuntu上安装蓝牙 ...

  2. Ext如何动态添加一行组件

    用的column布局,点击一个按钮能添加一行组件,如文本框,有下拉框等. 如: 效果: 实现方法如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...

  3. Windows UWP开发系列 – MessageDialog 和 ContentDialog

    MessageDialog 在Metro程序中,没有传统的窗口,当我们要用需要交互的消息提示时,在Win8时代,引入了一个MessageDialog来取代常用的MessageBox.使用方法如下: p ...

  4. Nagios 监控mysqlserver具体实现过程

    ,之后在页面就能够看到监控效果了 參考文章:http://os.51cto.com/art/201409/452605.htm

  5. JLInk 各种版本图片收集

    所有图片来自网络, 版权归原始所有者拥有. JLink V5 JLink V6 JLink V7 JLink V8 JLink V9 JLink Ultra JLink Pro

  6. STN1170 Multiprotocol OBD to UART Interpreter

    http://www.obdsol.com/stn1170/ STN1170 supports the following protocols: all legislated OBD II proto ...

  7. js:对象的创建(为prototype做铺垫)

    /**  *在js中并不存在类,所以能够直接通过Object来创建对象,可是使用这样的方式创建有一  *弊端:因为没有类的约束,无法实现对象的反复利用,而且没有一种规范约定,在操作时easy带来问题. ...

  8. mysql考试总结

    USE school; -- 班级表 CREATE TABLE class( cid TINYINT PRIMARY KEY AUTO_INCREMENT, caption VARCHAR(20) ) ...

  9. linux 网络设备驱动

    linux 网络驱动 谨以此文纪念过往的岁月 一.前言在linux中网络驱动也是一个大头,如何去理解网络驱动是作为一个linux驱动工程师必备的技能.不过同样的设备,在不同人的手中会有不同的效果,其原 ...

  10. javascript实现浏览器窗口传递参数

    a.html <html> <head> <title>主页面</title> <script language="javascript ...