Skip to content

Commit

Permalink
Updated the guide for setting up the MongoDB database (#15635)
Browse files Browse the repository at this point in the history
  • Loading branch information
alabhyajindal authored May 6, 2022
1 parent 991f406 commit 164f326
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 40 deletions.
Binary file not shown.
82 changes: 42 additions & 40 deletions files/en-us/learn/server-side/express_nodejs/mongoose/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,68 +518,70 @@ You will first need to [create an account](https://www.mongodb.com/atlas/databas

After logging in, you'll be taken to the [home](https://cloud.mongodb.com/v2) screen:

1. Click **Build a Cluster** button in the Clusters Overview section.
![Create a cluster on MongoDB Atlas.](mongodb_atlas_-_createcluster.jpg)
2. This will open the _Create New Cluster_ screen.
![Choose a cloud provider when using MongoDB Atlas.](mongodb_atlas_-_chooseproviderregion.jpg)
1. Click the **Build a Database** button in the _Database Deployments_ section.
![Create a database on MongoDB Atlas.](mongodb_atlas_-_createdatabase.jpg)

2. This will open the _Deploy a cloud database_ screen. Click on the **Create** button under the _Shared_ deployment option.
![Choose a deployment option when using MongoDB Atlas.](mongodb_atlas_-_deploy.jpg)

- Select any provider from the *Cloud Provider & Region* section. Different providers offer different regions.
- Select any region marked "FREE TIER AVAILABLE".
3. This will open the _Create a Shared Cluster_ screen.
![Choose a cloud provider when using MongoDB Atlas.](mongodb_atlas_-_createsharedcluster.jpg)

- Select any provider from the _Cloud Provider & Region_ section. Different regions offer different providers.
- _Cluster Tier_ and _Additional Settings_ don't need to be changed. You can change the name of your Cluster under _Cluster Name_. We are naming it `Cluster0` for this tutorial.
- Click the **Create Cluster** button (creation of the cluster will take some minutes).

3. You will return to the _Cluster Overview_ screen.
![Setup a collection on MongoDB Atlas.](mongodb_atlas_-_createcollection.jpg)
4. This will open the _Security Quickstart_ section.
![Set up the Access Rules on the Security Quickstart screen on MongoDB Atlas.](mongodb_atlas_-_securityquickstart.jpg)

- Click the **Collections** button.
- Enter a username and password. Remember to copy and store the credentials safely as we will need them later on. Click the **Create User** button.

4. This will open the _Collections_ section.
![Create a database on MongoDB Atlas.](mongodb_atlas_-_createdatabase2.png)
> **Note:** Avoid using special characters in your MongoDB user password as mongoose may not parse the connection string properly.
- Click the **Add My Own Data** button.
- Enter `0.0.0.0/0` in the IP Address field. This tells MongoDB that we want to allow access from anywhere. Click the **Add Entry** button.

5. This will open the _Create Database_ screen.
![Details during database creation on MongoDB Atlas.](mongodb_atlas_-_databasedetails.jpg)
> **Note:** It is a best practice to limit the IP addresses that can connect to your database and other resources. Here we allow a connection from anywhere because we don't know where the request will come from after deployment.
- Enter the name for the new database as `local_library`.
- Enter the name of the collection as `Collection0`.
- Click the **Create** button to create the database.
- Click the **Finish and Close** button.

6. You will return to the Collection screen with your database created.
![Database creation confirmation on MongoDB Atlas.](mongodb_atlas_-_databasecreated.jpg)
5. This will open the following screen. Click on the **Go to Databases** button.
![Go to Databases after setting up Access Rules on MongoDB Atlas](mongodb_atlas_-_accessrules.jpg)

- Click the _Overview_ tab to return the cluster overview.
6. You will return to the _Database Deployments_ screen. Click the **Browse Collections** button.
![Setup a collection on MongoDB Atlas.](mongodb_atlas_-_createcollection.jpg)

7. From the Cluster0 Overview screen click the **Connect** button.
![Configure a connection when after setting up a cluster in MongoDB Atlas.](mongodb_atlas_-_connectbutton.jpg)
8. This will open the Connect to Cluster screen.
![Choose a connection type when connecting with MongoDB Atlas.](connect_to_cluster_allowanywhere.png)
7. This will open the _Collections_ section. Click the **Add My Own Data** button.
![Create a database on MongoDB Atlas.](mongodb_atlas_-_adddata.jpg)

- Click the **Allow Access from Anywhere** button.
This will open a form with `0.0.0.0/0` pre-seeded for the IP Address. Click the **Add IP Address** button.
8. This will open the _Create Database_ screen.

> **Note:** It is a best practice to limit the IP addresses that can connect to your database and other resources. Here we allow a connection from anywhere because we don't know where the request will come from after deployment.
![Details during database creation on MongoDB Atlas.](mongodb_atlas_-_databasedetails.jpg)

- Enter the name for the new database as `local_library`.
- Enter the name of the collection as `Collection0`.
- Click the **Create** button to create the database.

- Enter a username and password and click **Create MongoDB User** button.
9. You will return to the _Collections_ screen with your database created.
![Database creation confirmation on MongoDB Atlas.](mongodb_atlas_-_databasecreated.jpg)

> **Note:** Avoid using special characters in your MongoDB user password as mongoose may not parse the connection string properly.
- Click the _Overview_ tab to return to the cluster overview.

- If you have completed the 2 previous steps, the button **Choose a connection method** will turn green.
- Click the **Choose a connection method** button.
10. From the Cluster0 _Overview_ screen click the **Connect** button.
![Configure connection after setting up a cluster in MongoDB Atlas.](mongodb_atlas_-_connectbutton.jpg)

9. You should now be able to access the _Choose a connection_ method tab.
11. This will open the _Connect to Cluster_ screen. Click the **Connect your application** option.
![Choose a connection type when connecting with MongoDB Atlas.](mongodb_atlas_-_chooseaconnectionmethod.jpg)

- Click the **Connect Your Application** option.

10. This will open the _Connect_ screen.
![Choose the Short SRV connection when setting up a connection on MongoDB Atlas.](mongodb_atlas_-_connectforshortsrv_2020-03.png)
12. You will now be shown the _Connect_ screen.
![Choose the Short SRV connection when setting up a connection on MongoDB Atlas.](mongodb_atlas_-_connectforshortsrv.jpg)

- Click the **Copy** button to copy the connection string.
- Save this string somewhere safe.
- Click the **Copy** icon to copy the connection string.
- Paste this in your local text editor.
- Update the password with your user's password.
- Replace test with `local_library`.
- Replace `myFirstDatabase` with `local_library`.
- Save the file containing this string somewhere safe.

You have now created the database, and have a URL (with username and password) that can be used to access it. This will look something like: `mongodb+srv://your_user_name:your_password@cluster0.a9azn.mongodb.net/local_library?retryWrites=true`
You have now created the database, and have a URL (with username and password) that can be used to access it. This will look something like: `mongodb+srv://your_user_name:your_password@cluster0.upbx7.mongodb.net/local_library?retryWrites=true&w=majority`

## Install Mongoose

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 164f326

Please sign in to comment.