最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: mongodb property insertmany is not a function - Stack Overflow

programmeradmin2浏览0评论
db.col.insertMany(
    [
        {
        "_id" : "tt0084726",
        "title" : "Star Trek II: The Wrath of Khan",
        "year" : 1982,
        "type" : "movie"
        },
        {
        "_id" : "tt0796366",
        "title" : "Star Trek",
        "year" : 2009,
        "type" : "movie"
        },
        {
        "_id" : "tt0084726",
        "title" : "Star Trek II: The Wrath of Khan",
        "year" : 1982,
        "type" : "movie"
        }
    ]
);

OS: LinuxMint 17.3 Rosa MongoDB: db version v2.6.12

I am participating in a course by the University of MongoDB. When I input the command as above into mongo shell, an Error occurs: TypeError: Property 'insertMany' of object test.col is not a function how to solve it? I have read the docs but still failed.

db.col.insertMany(
    [
        {
        "_id" : "tt0084726",
        "title" : "Star Trek II: The Wrath of Khan",
        "year" : 1982,
        "type" : "movie"
        },
        {
        "_id" : "tt0796366",
        "title" : "Star Trek",
        "year" : 2009,
        "type" : "movie"
        },
        {
        "_id" : "tt0084726",
        "title" : "Star Trek II: The Wrath of Khan",
        "year" : 1982,
        "type" : "movie"
        }
    ]
);

OS: LinuxMint 17.3 Rosa MongoDB: db version v2.6.12

I am participating in a course by the University of MongoDB. When I input the command as above into mongo shell, an Error occurs: TypeError: Property 'insertMany' of object test.col is not a function how to solve it? I have read the docs but still failed.

Share Improve this question edited Jan 5, 2018 at 5:06 Mikko 1,9472 gold badges26 silver badges37 bronze badges asked Jun 2, 2016 at 7:38 muzikmoemuzikmoe 1211 gold badge3 silver badges10 bronze badges 3
  • 3 what version of mongo are you using ? – jack blank Commented Jun 2, 2016 at 7:40
  • MongoDB shell version: 2.6.12 – muzikmoe Commented Jun 2, 2016 at 7:42
  • please use that link you can find the detail : stackoverflow.com/a/68662249/10936485 – Sonu P. Commented Aug 5, 2021 at 7:27
Add a comment  | 

4 Answers 4

Reset to default 10

I had a similar problem. You need to have version 3.2

> New in version 3.2.

You need to update your version of mongodb to use insertMany.

It's not so hard. I did it a couple weeks ago to use insertMany

I am newbie in MongoDB , I got similar error in another scenario. I am adding that also an answer here, any future reader may find useful!

db.users.insertMany ([{name:"Ajith",status:"pending",age:25}, {name:"Kumar",status:"withheld",age:40}, {name:"Lal",status:"passed",age:34}, {name:"Tishil Joppen",status:"high",age:28}])

I forgot to include the square brackets , and got the same error!!

since your Mongo version is MongoDB: db version v2.6.12 (< 3.2) you need to run

db.col.insert(
[
    {
    "_id" : "tt0084726",
    "title" : "Star Trek II: The Wrath of Khan",
    "year" : 1982,
    "type" : "movie"
    },
    {
    "_id" : "tt0796366",
    "title" : "Star Trek",
    "year" : 2009,
    "type" : "movie"
    },
    {
    "_id" : "tt0084726",
    "title" : "Star Trek II: The Wrath of Khan",
    "year" : 1982,
    "type" : "movie"
    }
]);

Ensure your table name is plural:

db.cols.insertMany

发布评论

评论列表(0)

  1. 暂无评论