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

来源:互联网 发布:知乎搜索引擎入口 编辑:程序博客网 时间:2024/05/22 04:57
1.当前数据库版本 > db.version(); 3.2.32.进行对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:15.使用小写的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 }> 

0 0
原创粉丝点击