Files
web/MongoDB/README.md
2026-03-17 01:00:11 +08:00

160 lines
4.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# MongoDB 集合说明yh_web
默认数据库名:`yxd-agent-testing`(见 `server/config/constants.go`)。
以下为功能涉及的集合及文档结构,**线上已有的集合也按此结构对照**;缺失的集合可用 `create_collections.js` 创建。
---
## 1. sites站点
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| name | string | 站点名称 |
| domain | string | 域名 |
| description | string | 描述(可选) |
| created_at | string | 创建时间(如 RFC3339 |
---
## 2. pages网页属于某站点
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| site_id | string | 站点 IDObjectID 十六进制字符串) |
| slug | string | 路径标识index, about, ... |
| title | string | 标题 |
| type | string | 类型homepage / page |
| content | string | HTML 或 JSON 字符串(首页为 HomepageData JSON |
| updated_at | string | 更新时间 |
**索引建议**`{ site_id: 1, slug: 1 }` 唯一,便于按站点+slug 查首页/子页。
---
## 3. site_assets站点资源/上传文件)
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| site_id | string | 站点 ID |
| name | string | 文件名/显示名 |
| file_path | string | 相对路径 |
| size | int64 | 字节数 |
| content_type | string | MIME 类型 |
| created_at | string | 创建时间 |
**索引建议**`{ site_id: 1 }`
---
## 4. users用户
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| username | string | 用户名 |
| mobile | string | 手机号(可选) |
| email | string | 邮箱 |
| password | string | 密码哈希 |
| role | string | 角色名 |
| role_id | int | 9527=超级管理员1=普通用户 |
| is_beta | bool | 是否体验用户(可选) |
| trial_start_date | string/date | 试用开始(可选) |
| trial_end_date | string/date | 试用结束(可选) |
| lastLogin | string | 最后登录(可选) |
| llm | string | LLM 配置(可选) |
**索引建议**`{ username: 1 }` 唯一,`{ mobile: 1 }` 可选。
---
## 5. workspaces工作空间
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| name | string | 名称 |
| user_id | string | 用户 ID |
| created_at | string | 创建时间 |
**索引建议**`{ user_id: 1 }`
---
## 6. conversations对话
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| title | string | 标题 |
| user_id | string | 用户 ID |
| workspace_id | string | 工作空间 ID |
| created_at | string | 创建时间 |
| updated_at | string | 更新时间 |
**索引建议**`{ user_id: 1 }``{ workspace_id: 1 }`
---
## 7. messages消息统计用
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| conversation_id | string | 对话 ID |
| role | string | user / assistant / system |
| content | string | 内容 |
| created_at | string | 创建时间 |
**说明**:当前仅统计接口使用,若功能未实现可先建空集合。
---
## 8. files文件统计用
| 字段 | 类型 | 说明 |
|------|------|------|
| _id | ObjectID | 主键 |
| user_id | string | 用户 ID |
| name | string | 文件名 |
| file_path | string | 存储路径 |
| size | int64 | 字节数 |
| created_at | string | 创建时间 |
**说明**:当前仅统计接口使用,若功能未实现可先建空集合。
---
## 9. system_config系统配置按 _id 区分类型)
单集合,`_id` 为字符串键,不同键对应不同配置结构。
- ** _id: "payment"** — 支付配置
- wechat: { app_id, mch_id, api_key, api_key_v3, enabled }
- alipay: { app_id, private_key, alipay_public_key, enabled }
- **_id: "sms_platform"** — 短信配置
- provider, access_key, secret_key, sign_name, template_id, enabled
**索引**:默认 _id 唯一即可。
---
## 使用方式
在项目根目录执行(需已安装 mongosh
```bash
mongosh "mongodb://localhost:27017" --file MongoDB/create_collections.js
```
或进入 mongosh 后:
```js
use("yxd-agent-testing")
// 再粘贴 create_collections.js 中的创建与索引语句
```