TypeError: Cannot read property 'close' of undefined

Hi,

I am unable to connect to the Atlas Cluster (Free Tier) in my app. I’m running on MacOS, so I’ve edited the dotenv_unix.env file to look like this (some values changes):

SECRET_KEY=whatever
MFLIX_DB_URI=mongodb+srv://m220student:m220password@cluster0-1tmnb.mongodb.net
MFLIX_NS=sample_mflix
PORT=5000

Every time I try to run npm start or run the basic connection test, I get the error from the subject.
Things I’ve already tried:

  • Trying every possible URI type from the Atlas website.
  • Following this topic: SOLVED: TypeError: Cannot read property ‘close’ of undefined.
  • Creating new db users.
  • Increasing the connection timeout.
  • Using the Windows .env file.
  • Whitelisting all IP addresses.
  • Running the code on a different machine.
  • Re-downloading the app package.
  • Rebuilding the npm packages.

Connecting via Atlas and Mongo Shell works great, there is very minimal lag.

I am unable to connect using the same command.

  • Can you make sure IP is whitelisted.
  • If yes, check the indentation in .env file
  • Make sure to run the test commands from mflix-js directory only

If nothing works, please share the contents of .env file.

Kanika

2 Likes