I wrote following code to connect mongodb through native driver which has been install with npm install mongodb --save
Check your mongo version
mongo --version
If you are using version >= 3.1.0 change you mongo connection file to ->
MongoClient.connect("mongodb://localhost:27017/YourDB", {
useNewUrlParser: true,
useUnifiedTopology: true
})
For details about the useUnifiedTopology
option added in 3.2.1, see https://github.com/mongodb/node-mongodb-native/releases/tag/v3.2.1