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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章