'MongoDB Laravel works local but not on host

Would anyone know how to fix this I can't find any method that works online. My mongodb does work local but not on host.

I'm using laravel with the following:

    "require": {
        "php": "^7.3|^8.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "jenssegers/mongodb": "^3.8",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/socialite": "^5.2",
        "laravel/tinker": "^2.5",
        "livewire/livewire": "^2.10",
        "martinbean/socialite-discord-provider": "1.2"
    },
No suitable servers found (`serverSelectionTryOnce` set): [connection closed calling hello on 'neptuneservices-shard-00-00.vrb68.mongodb.net:27017']
DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DSN=mongodb+srv://Bacio001:<Password>@neptuneservices.vrb68.mongodb.net/TicketDashboard?authSource=admin&replicaSet=atlas-9tln1c-shard-0&readPreference=primary&appname=MongoDB%20Compass&ssl=true
DB_DATABASE=TicketDashboard
        'mongodb' => [
            'driver' => 'mongodb',
            'dsn' => env('DB_DSN'),
            'database' =>


Solution 1:[1]

Your connection information on the host is incorrect when you see this error. Be sure to enter the server address, username, password, database name, etc. carefully based on what is on the server.

I suggest you follow the link below https://github.com/jenssegers/laravel-mongodb#configuration

Solution 2:[2]

Once I had a similar problem with different pieces of information in the .env and config/database.php files, be sure that both files had the same information.

You also can try to clean the cache of applications.

php artisan config:clear

php artisan cache:clear

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Keyvan Gholami
Solution 2 Karl Hill