I suspect it is due to special character “!” in your password
You have to escape it or use Uriencoder or call password separately instead of using it in connect string or change PWD to a simple one
It works because you are connecting to local mongodb without access control enabled
Your requirement is to connect to Atlas with userid/PWD
Try to replicate the same in your local instance and see if you can connect(enable access control and create user and PWD with special character)