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 | 站点 ID(ObjectID 十六进制字符串) |
| 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 | 手机号(可选) |
| 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):
mongosh "mongodb://localhost:27017" --file MongoDB/create_collections.js
或进入 mongosh 后:
use("yxd-agent-testing")
// 再粘贴 create_collections.js 中的创建与索引语句