E QUERY [thread1] TypeError: db.foo.batchInsert is not a function :

1.当前数据库版本

 > db.version(); 
3.2.3

2.进行对foo集合批量插入

> db.foo.batchInsert([{"_id": 0},{"_id": 1},{"_id": 2}])db.foo.batchInsert([{"_id": 0},{"_id": 1},{"_id": 2}])
2016-03-31T10:19:59.718+0800 E QUERY    [thread1] TypeError: db.foo.batchInsert is not a function :
@(shell):1:1

    插入不成功会有以下 E QUERY    [thread1] TypeError: db.foo.batchInsert is not a function :报错
关于batchInsert,在<mongdb权威指南中>使用version 2.4.0的mongodb,其中使用batchInsert函数进行对foo集合进行批量插入

3.在mongodb新版的v3.2.3中,batchInsert已经被废弃掉了,所以再用batchInsert执行批量插入是会报错:batchInsert is not a function 
在v3.2.3版本直接使用insert实现对foo集合批量插入(注意的是insert大小写)

4.如果使用 db.foo.Insert,会插入不成功
> db.foo.Insert([{"_id": 0},{"_id": 1},{"_id": 2}])db.foo.Insert([{"_id": 0},{"_id": 1},{"_id": 2}])
2016-03-31T10:28:31.195+0800 E QUERY    [thread1] TypeError: db.foo.Insert is not a function :
@(shell):1:1

5.使用小写的db.foo.insert,执行成功
 
 > db.foo.insert([{"_id": 0},{"_id": 1},{"_id": 2}])db.foo.insert([{"_id": 0},{"_id": 1},{"_id": 2}])
BulkWriteResult({
        "writeErrors" : [
                {
                        "index" : 0,
                        "code" : 11000,
                        "errmsg" : "E11000 duplicate key error collection: test.foo index: _id_ dup key: { : 0.0 }",
                        "op" : {
                                "_id" : 0
                        }
                }
        ],
        "writeConcernErrors" : [ ],
        "nInserted" : 0,
        "nUpserted" : 0,
        "nMatched" : 0,
        "nModified" : 0,
        "nRemoved" : 0,
        "upserted" : [ ]
})
> 

6.对插入结果使用db.foo.find()进行查询,批量插入成功

> db.foo.find()
{ "_id" : ObjectId("56f8d8149caa5bade991729b"), "bar" : "ba" }
{ "_id" : ObjectId("56f8d9989caa5bade991729c"), "bar" : "2" }
{ "_id" : ObjectId("56f8d99b9caa5bade991729d"), "bar" : "3" }
{ "_id" : ObjectId("56f8d99d9caa5bade991729e"), "bar" : "4" }
{ "_id" : ObjectId("56f8d9a69caa5bade991729f"), "bar" : "5" }
{ "_id" : 0 }
{ "_id" : 1 }
{ "_id" : 2 }
> 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值