diff --git a/README.md b/README.md index 78eb694..5635456 100644 --- a/README.md +++ b/README.md @@ -72,14 +72,35 @@ in your sample app: cp .env.example .env ``` -### Configure your MongoDB Credentials +### Set the Default Connection Environment Variable -In your ``.env`` file, set or update the following variables, replacing the -```` placeholder with your MongoDB connection string: +Open the ``.env`` file in an editor and set the value of the ``DB_CONNECTION`` +variable to ``mongodb`` as shown in the following example: ``` DB_CONNECTION=mongodb -DB_URI= +``` + +### Make a Copy of the Example Environment File + +Run the following command to use the example environment file +in your sample app: + +``` +cp .env.example .env +``` + +### Configure your MongoDB Credentials + +In the ``.env`` file, replace the value of the ``DB_URI`` variable with your +MongoDB connection string. + +For example, if your connection string is +"mongodb+srv://myUser:myPass123@mongo0.example.com/", +your ``DB_URI`` variable matches the following line: + +``` +DB_URI="mongodb+srv://myUser:myPass123@mongo0.example.com/" ``` If you need to create a MongoDB Atlas deployment, see the @@ -90,6 +111,9 @@ If you already have a MongoDB Atlas deployment, see the [Create a Connection String](https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/quick-start/create-a-connection-string) step of the Quick Start. +> [!NOTE] +> Make sure these variables in your ``.env`` file are undefined in the shell in which you run your application. Environment variables in the shell take precedence over the ones in the ``.env`` file. + ### Start the PHP Built-in Webserver To start the webserver, run the following command from the application root diff --git a/my-app/config/database.php b/my-app/config/database.php index 368ed5a..59510b5 100644 --- a/my-app/config/database.php +++ b/my-app/config/database.php @@ -16,7 +16,7 @@ | */ - 'default' => env('DB_CONNECTION', 'mongodb'), + 'default' => env('DB_CONNECTION'), /* |-------------------------------------------------------------------------- @@ -32,7 +32,7 @@ 'connections' => [ 'mongodb' => [ 'driver' => 'mongodb', - 'dsn' => env('DB_URI', ''), + 'dsn' => env('DB_URI'), 'database' => 'sample_mflix', ],