How to use MongoDB with promises in Node.js?

Your approach is almost correct, just a tiny mistake in your argument

var MongoClient = require('mongodb').MongoClient
var url="mongodb://localhost:27017/example"
MongoClient.connect(url)
  .then(function (db) { // <- db as first argument
    console.log(db)
  })
  .catch(function (err) {})

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)