Setting Up an Online MongoDB Database
1. Create a MongoDB Atlas Account
- Open a new tab in your web browser and go to account.mongodb.com/account/register.
- Fill out the required information and create your account.
2. Create a New Project
- After setting up your account, click on the âNew Projectâ button and give it a name (e.g., âLibreChatâ).
3. Build a Database
- Click on the âBuild a Databaseâ button.
4. Choose the Free Tier
- Select the âShared Clustersâ option, which is the free tier.
5. Name Your Cluster
- Give your cluster a name (e.g., âLibreChat-Clusterâ) and click âCreate Clusterâ.
6. Set Up Database Credentials
- Click on the âDatabase Accessâ option in the sidebar.
- Click on the âAdd New Database Userâ button.
- Enter a username and a secure password, then click âAdd Userâ.
7. Configure Network Access
- Click on the âNetwork Accessâ option in the sidebar.
- Click on the âAdd IP Addressâ button.
- Select âAllow Access from Anywhereâ and click âConfirmâ.
8. Get Your Connection String
- Click on the âDatabasesâ option in the sidebar.
- Click on the âConnectâ button.
- Select âConnect Your Applicationâ.
- Copy the connection string provided.
- Replace
<password>
in the connection string with the password you set in Step 6. Remove the<>
characters around the password. - Remove
&w=majority
from the end of the connection string. - Add your desired database name (e.g., âLibreChatâ) after the host name in the connection string.
Your final connection string should look something like this:
Connection String
mongodb+srv://username:[email protected]/LibreChat?retryWrites=true
9. Update the .env File
- In your LibreChat project, open the
.env
file. - Find the
MONGO_URI
variable and paste your connection string:
.env
MONGO_URI=mongodb+srv://username:[email protected]/LibreChat?retryWrites=true
Thatâs it! Youâve now set up an online MongoDB database for LibreChat using MongoDB Atlas, and youâve updated your LibreChat application to use this database connection. Your application should now be able to connect to the online MongoDB database.
Note about Docker
âïž
Docker