I create NodeJS V8 app and use mongoDB local server.
I had mongoDB version ^2.2.34 and connect to DB
let mongodb = require('mongodb');
let mongoClient = mongodb.MongoClient;
let connection = mongoClient.connect('mongodb://localhost:27017/Test');
let getCollection = function (c) {
return connection.then(function (db) {
return db.collection(c);
});
};
It worked. I update my mongoDB version to ^3.0.1 and have error
(node:16320) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: db.collection is not a function
Why in new version it isn't work and how I can change code?
Copyright Notice:Content Author:「Aksenov Vladimir」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48464522/mongodb-3-0-and-mongodb-2-2