Connection Error to MongoDB Atlas

System Information
  • Strapi Version: 3.1.4
  • Operating System: Ubuntu 21.10
  • Database: MongoDB
  • Node Version: 12.18.3
  • NPM Version: 6.14.6

I get an error while connecting to MongoDB Atlas Cluster.

[2022-04-02T11:50:29.136Z] debug ⛔️ Server wasn't able to start properly.
[2022-04-02T11:50:29.139Z] error Error connecting to the Mongo database. Server selection timed out after 30000 ms
npm ERR! errno 1
npm ERR! backend@0.1.0 develop: `strapi develop`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the backend@0.1.0 develop script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/om/.npm/_logs/2022-04-02T11_50_29_161Z-debug.log

Now I have done everything from all the github issues suggestions and also tried various other things.

  1. Whitelisted my IP.
  2. Changed DB users.
  3. Tried changing database types, ( sql, postgre)
  4. Made sure mongo is running in the backend.

Here are the contens of the log :

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'develop' ]
2 info using npm@6.14.6
3 info using node@v12.18.3
4 verbose run-script [ 'predevelop', 'develop', 'postdevelop' ]
5 info lifecycle backend@0.1.0~predevelop: backend@0.1.0
6 info lifecycle backend@0.1.0~develop: backend@0.1.0
7 verbose lifecycle backend@0.1.0~develop: unsafe-perm in lifecycle true
8 verbose lifecycle backend@0.1.0~develop: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/media/om/Data/JAMstack - Udemy/back-end/node_modules/.bin:/home/om/anaconda3/condabin:/home/om/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
9 verbose lifecycle backend@0.1.0~develop: CWD: /media/om/Data/JAMstack - Udemy/back-end
10 silly lifecycle backend@0.1.0~develop: Args: [ '-c', 'strapi develop' ]
11 silly lifecycle backend@0.1.0~develop: Returned: code: 1  signal: null
12 info lifecycle backend@0.1.0~develop: Failed to exec develop script
13 verbose stack Error: backend@0.1.0 develop: `strapi develop`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid backend@0.1.0
15 verbose cwd /media/om/Data/JAMstack - Udemy/back-end
16 verbose Linux 5.13.0-28-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "develop"
18 verbose node v12.18.3
19 verbose npm  v6.14.6
20 error code ELIFECYCLE
21 error errno 1
22 error backend@0.1.0 develop: `strapi develop`
22 error Exit status 1
23 error Failed at the backend@0.1.0 develop script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

This is a complete new project, tried creating multiple new projects, still the same issue for all of them, even for new Atlas clusters/projects.
It just connects sometimes , and then doesn’t connect later. I have no idea how to go ahead as I am a beginner. Any kind of help will be appreciated.
I will keep on updating this with the Github Issues Links and other methods which I will try more.