# T032 — Mongo Run store 與索引 > Status: `done` > Milestone: `M3` > Est. change: `~200 lines` ## Goal 完成後,MonStore 能持久化獨立 run、guarded 更新並用可索引查詢提供批次分頁。 ## Depends on - T031 ## Inputs - 讀取 / 依賴: - 檔案:`apps/backend/internal/module/scout/repository/mongo.go` - 既有能力 / API:go-zero mon.Model、Mongo options、Run repository contract - Spec 段落:§3、§7、§8 ## Outputs ### 程式變更(預期路徑) | 路徑 | 動作 | 說明 | |------|------|------| | `apps/backend/internal/module/scout/repository/mongo.go` | edit | 加入 scout_runs model、create/get/list、guarded status/count updates、owner filters。 | | `apps/backend/internal/module/scout/repository/mongo_indexes.go` | add | 建立 run list、run posts、owner identity 唯一性所需索引。 | | `apps/backend/internal/module/scout/repository/mongo_run_test.go` | add | 在可控 Mongo 環境驗證 guard、sort 與 uniqueness。 | ### 行為變更 - 每個更新同時限定 owner、run ID 與 expected status;未命中回明確 conflict/not found。 ### API / 契約(若有) - run list sort 為 created_at desc、_id desc;pageSize 最大 50。 ## Out of scope - 不修改其他 module collection,不清洗所有歷史 duplicates。 ## Acceptance - [x] 必要索引透過既有 cmd/init 冪等建立;無可用 Mongo 時測試明確 skip。 - [ ] 指令: ```bash cd apps/backend && go test ./internal/module/scout/repository -run MongoRun -count=1 ``` 驗收結果:MongoRun integration test 在未設定 Mongo 時明確 skip;cmd/init build 通過。 ## Notes 若專案既有 index bootstrap 機制,沿用它,不在 request path 每次建索引。