Trying to connect to mongodb on MongoDB cloud from NodeJS app hosted on Heroku. Using mongodb ^3.2.3 and MongoDBClient, locally on my machine works great but after deployment to Heroku, getting the error above : "MongoError: MongoClient must be connected before calling MongoClient.prototype.db"
const uri = "mongodb+srv://myuser:mypass@mongodbcluster/test?retryWrites=true";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
db = client.db("collection"); // <-- this is where it fails
...