MongoDB
When to Use
- Querying conversations, messages, or agents in LibreChat’s MongoDB
- Any script that needs pymongo in the Railway environment
Connection
Python Packages in Railway
Packages are baked into the Docker image via Forge/Configs/LibreChat_Service/Dockerfile.librechat.
To add a new package, add it to the pip install line in the Dockerfile and redeploy.
Installed packages:
pymongo— MongoDB driverdnspython— pymongo dependency
Collections & Schemas
conversations
| Field | Type | Description |
|---|---|---|
conversationId | string (UUID) | Primary identifier |
title | string | Conversation title |
messages | list[ObjectId] | References to messages collection |
updatedAt | datetime | Last update timestamp |
user | ObjectId | User who owns the conversation |
messages
| Field | Type | Description |
|---|---|---|
messageId | string (UUID) | Primary identifier |
conversationId | string (UUID) | Parent conversation |
sender | string | "User" or agent display name |
isCreatedByUser | bool | True for user messages |
text | string | Plain text of the message (may be empty for tool-heavy turns) |
content | list[dict] | Structured content items (see below) |
tokenCount | int | Token count for the message |
createdAt | datetime | Creation timestamp |
content item types
text: {"type": "text", "text": "..."}
tool_call:
agents
| Field | Type | Description |
|---|---|---|
id | string | Agent ID (agent_...) |
name | string | Display name |
instructions | string | System prompt / instructions |
model_parameters | dict | Model-specific settings |
tools | list | Enabled tools |
Rules
- Never expose MONGO_URI in conversation output — redact in transcripts
MONGO_URIis read from/proc/1/environ— never hardcode connection strings- Always close connections or use context managers for scripts that run standalone