SOLVED: TypeError: Cannot read property 'close' of undefined

Hi Everyone,

Hope you are enjoying the course! If anyone is experiencing the below issue like this:

TypeError: Cannot read property 'close' of undefined

  17 | 
  18 |   async teardown() {
> 19 |     await
     |                                   ^
  20 |     await super.teardown()
  21 |   }
  22 | 

  at MongoEnvironment.teardown (test/config/mongoEnvironment.js:19:35)                                                    
      at Generator.throw (<anonymous>)

Please make sure few things:

  • .env file is named as .env and not ‘dotenv’ file
  • The connection string mentioned in the file should look like this: “mongodb+srv://”
  • You should be able to connect the cluster from your system. You can check this by connecting to the cluster from your command line.

Most common reasons if you are unable to connect to your cluster are:

  • Firewall is enabled
  • Anti-virus is blocking the requests
  • IP whitelisting is not done on the cluster from

Even after doing all the above, you are facing the same issue and the latency is high becsuse of free tier location, then try increasing the connectTimeoutMS in the test file. :slight_smile:
This is great post here which will help you in guiding for the code change.

Please feel free to post a new topic if you are still unable to resolve the issue! :slight_smile: