TypeError: db.collection is not a function

后端 未结 18 2457
青春惊慌失措
青春惊慌失措 2020-11-27 03:09

I am trying to post data to database that I have created on mLab and I am getting this error but I don\'t know whats going wrong.I also have read previously asked question o

18条回答
  •  [愿得一人]
    2020-11-27 03:13

    Had this issue as well, I was following a tutorial in which the presenter was using the collection as a function. It never worked for me. What I discovered was that the presenter was using version 2.3.4 of the mongodb npm module. the module is well into version 3.x.x now. When I changed the package.json file to request the 2.x.x version of the mogodb npm module, suddenly everything worked.

    What I believed happened was that the module was altered to change the collection into a different object. Don't know how to use the new version but if you specify that you want the 2.x.x version, the old way should work. Specifically I can confirm that (coming from my package.json file, "dependencies" section) "mongodb": "^2.2.31" works.

    Best way:

    $> npm install mongodb@2.2.31 --save
    

提交回复
热议问题