> ## 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 結構描述；程式碼為 `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.