Skip to main content

LibreChat is joining ClickHouse. Learn more

LibreChat

MongoDB Community Server

为您的 LibreChat 数据库设置 MongoDB Community Server。

下载 MongoDB Community Server

安装 MongoDB Community Server

请按照您操作系统的安装说明安装 MongoDB Community Server。

创建数据目录

MongoDB 需要一个数据目录来存储其数据文件。请在您的系统上创建一个目录,用于存放 MongoDB 数据文件(例如 /path/to/data/directory)。

启动 MongoDB 服务器

  • 打开终端或命令提示符。
  • 导航至 MongoDB 安装目录(例如 /path/to/mongodb/bin)。
  • 运行以下命令以启动 MongoDB 服务器,并将 /path/to/data/directory 替换为您在上一步中创建的数据目录的路径:
./mongod --dbpath=/path/to/data/directory

配置 MongoDB 以实现远程访问(可选)

如果您计划从远程位置(例如,不同的机器或托管在其他地方的 LibreChat 实例)访问 MongoDB 服务器,则需要配置 MongoDB 以进行远程访问:

  • 创建一个配置文件(例如 /path/to/mongodb/config/mongodb.conf),内容如下:
# Network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0
  • 如果 MongoDB 服务器正在运行,请将其停止。
  • 使用配置文件启动 MongoDB 服务器:
./mongod --config /path/to/mongodb/config/mongodb.conf

获取连接字符串

您的 MongoDB Community Server 连接字符串格式如下:

mongodb://[hostname]:[port]

将 [hostname] 替换为运行 MongoDB 的机器的 IP 地址或主机名,并将 [port] 替换为端口号(通常为 27017)。

更新 .env 文件

  • 在你的 LibreChat 项目中,打开 .env 文件。
  • 找到 MONGO_URI 变量并粘贴您的连接字符串:
MONGO_URI=mongodb://[hostname]:[port]

就是这样!你现在已经为 LibreChat 设置好了 MongoDB Community Server。你的 LibreChat 应用程序应该能够使用你提供的连接字符串连接到本地的 MongoDB 实例。

关于 Docker 的说明

Docker

注意: 如果您正在使用 Docker 运行 LibreChat,则需要使用 docker-compose.override.yml 文件。此覆盖文件允许您阻止安装随附的 MongoDB 实例。相反,您的 LibreChat Docker 容器将使用您刚刚设置的本地 MongoDB Community Server 数据库。有关使用覆盖文件的更多信息,请参阅我们的 Docker Override Guide。

示例:

services:
  api:
    environment:
    - MONGO_URI=mongodb://user:pass@host1:27017,host2:27017,host3:27017/LibreChat?authSource=admin&replicaSet=setname

这篇指南怎么样?