---
title: "MongoDB Community Server"
description: "Setting up a MongoDB Community Server for your LibreChat database."
---

# Setting Up a MongoDB Community Server

## 1. Download MongoDB Community Server
- Go to the official MongoDB website: [https://www.mongodb.com/try/download/community](https://www.mongodb.com/try/download/community)
- Select your operating system and download the appropriate package.

## 2. Install MongoDB Community Server
Follow the installation instructions for your operating system to install MongoDB Community Server.

## 3. Create a Data Directory
MongoDB requires a data directory to store its data files. Create a directory on your system where you want to store the MongoDB data files (e.g., `/path/to/data/directory`).

## 4. Start the MongoDB Server
- Open a terminal or command prompt.
- Navigate to the MongoDB installation directory (e.g., `/path/to/mongodb/bin`).
- Run the following command to start the MongoDB server, replacing `/path/to/data/directory` with the path to the data directory you created in Step 3:

```sh filename="Start the MongoDB Server"
./mongod --dbpath=/path/to/data/directory
```

## 5. Configure MongoDB for Remote Access (Optional)
If you plan to access the MongoDB server from a remote location (e.g., a different machine or a LibreChat instance hosted elsewhere), you need to configure MongoDB for remote access:

- Create a configuration file (e.g., `/path/to/mongodb/config/mongodb.conf`) with the following content:

```yaml filename="mongodb.conf"
# Network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0
```
- Stop the MongoDB server if it's running.
- Start the MongoDB server with the configuration file:

```yaml filename="Start the MongoDB server"
./mongod --config /path/to/mongodb/config/mongodb.conf
```

## 6. Get the Connection String
The connection string for your MongoDB Community Server will be in the following format:

```sh filename="Connection String"
mongodb://[hostname]:[port]
```
Replace `[hostname]` with the IP address or hostname of the machine where MongoDB is running, and `[port]` with the port number (usually 27017).

## 7. Update the .env File
- In your LibreChat project, open the `.env` file.
- Find the `MONGO_URI` variable and paste your connection string:

```sh filename=".env"
MONGO_URI=mongodb://[hostname]:[port]
```

That's it! You've now set up a MongoDB Community Server for LibreChat. Your LibreChat application should be able to connect to the local MongoDB instance using the connection string you provided.

## Note about Docker

<Callout type="note" title="Docker">
**Note:** If you're using LibreChat with Docker, you'll need to utilize the `docker-compose.override.yml` file. This override file allows you to prevent the installation of the included MongoDB instance. Instead, your LibreChat Docker container will use the local MongoDB Community Server database you've just set up. For more information on using the override file, please refer to our [Docker Override Guide](/docs/configuration/docker_override).

**Example:**
```yaml filename="docker-compose.override.yml"
services:
  api:
    environment:
    - MONGO_URI=mongodb://user:pass@host1:27017,host2:27017,host3:27017/LibreChat?authSource=admin&replicaSet=setname
```
</Callout>
