> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Spelling Preferences 集合

`spellingPreferences` 保存每个用户的词典：用户通过编辑器拼写检查中的 "Add to dictionary" 添加的单词。每个用户一个文档。由 `web` 负责，没有 Mongoose schema；代码为 `services/web/app/src/Features/Spelling/LearnedWordsManager.mjs`。

#### 字段

| 字段 | 类型 | 含义 | 来源 |
| - | - | - | - |
| `_id` | ObjectId | 文档 id，由 upsert 创建。 | `LearnedWordsManager.mjs:21-31` |
| `token` | String | 用户的 id。尽管名称如此，拼写路由传入的是已登录用户的 id（`SessionManager.getLoggedInUserId`）。 | `LearnedWordsManager.mjs:23` |
| `learnedWords` | Array of String | 用户添加的单词。 | `LearnedWordsManager.mjs:26` |

#### 谁写入

| 代码 | 作用 |
| - | - |
| `LearnedWordsManager.mjs:13-32` (`learnWord`) | `POST /spelling/learn` (`services/web/app/src/router.mjs:1037-1041`, `services/web/app/src/Features/Spelling/SpellingController.mjs:45-58`): 以 upsert 方式对该单词执行 `$addToSet`。当列表将超过 `Settings.maxDictionarySize` 字节时拒绝。 |
| `LearnedWordsManager.mjs:38-47` (`unlearnWord`) | `POST /spelling/unlearn` (`router.mjs:1043-1047`, `SpellingController.mjs:66-79`): 对该单词执行 `$pull`。 |
| `LearnedWordsManager.mjs:84-86` (`deleteUsersLearnedWords`) | 删除该文档。它唯一的封装 `SpellingHandler.deleteUserDictionary`（`services/web/app/src/Features/Spelling/SpellingHandler.mjs:24-26`）在 web 及其模块中没有调用方。 |

#### 谁读取

| 代码 | 作用 |
| - | - |
| `LearnedWordsManager.mjs:52-67` (`getLearnedWords`) | 返回去重后的单词。 |
| `services/web/app/src/Features/Project/ProjectController.mjs:671` | 打开项目时把词典发送给编辑器（`SpellingHandler.getUserDictionary`）。 |

#### 索引

| 名称 | 键 | 选项 | 迁移 |
| - | - | - | - |
| `token` | `{ token: 1 }` | | `tools/migrations/20190912145027_create_spellingPreferences_indexes.mjs` |

#### 说明

* 该索引不是唯一索引；对 `token` 的 upsert 让每个用户只保留一个文档。
* 删除用户不会删除此文档。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.