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 }
> 

发布了145 篇原创文章 · 获赞 111 · 访问量 102万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章