db.collection is not a functionというerrの解決方法
db.collection is not a functionというerrの解決方法が判明したのでシェア。
★エラー内容
[vagrant@localhost nodejs]$ node mongo.js
current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
connected to db
/home/vagrant/nodejs/node_modules/mongodb/lib/topologies/server.js:301
throw err;
^
TypeError: db.collection is not a function
at /home/vagrant/nodejs/mongo.js:7:5
at /home/vagrant/nodejs/node_modules/mongodb/lib/utils.js:410:17
★原因と対策
どうやらmongoDBのversionUPでお作法が変わったようです。
dbを明示的に定義する必要が発生したようです(以下)