backend/generate/database/mongo/2025100900000004_user_role....

22 lines
762 B
Plaintext
Raw Permalink Normal View History

2025-11-14 14:40:56 +00:00
// 1. 唯一索引:使用者 UID 必須唯一(一個使用者只能有一個角色)
2025-11-12 08:17:23 +00:00
db.user_role.createIndex({"uid": 1}, {unique: true});
2025-11-14 14:40:56 +00:00
// 2. 查詢索引:按角色 ID 查詢(用於獲取某角色的所有使用者)
2025-11-12 08:17:23 +00:00
db.user_role.createIndex({"role_id": 1});
2025-11-14 14:40:56 +00:00
// 3. 查詢索引:按 Brand 查詢
2025-11-12 08:17:23 +00:00
db.user_role.createIndex({"brand": 1});
2025-11-14 14:40:56 +00:00
// 4. 查詢索引:按狀態查詢
2025-11-12 08:17:23 +00:00
db.user_role.createIndex({"status": 1});
2025-11-14 14:40:56 +00:00
// 5. 複合索引:按 Brand 和角色 ID 查詢(常用組合)
2025-11-12 08:17:23 +00:00
db.user_role.createIndex({"brand": 1, "role_id": 1});
2025-11-14 14:40:56 +00:00
// 6. 複合索引:按 Brand 和狀態查詢
2025-11-12 08:17:23 +00:00
db.user_role.createIndex({"brand": 1, "status": 1});
2025-11-14 14:40:56 +00:00
// 7. 時間戳索引:用於排序和時間範圍查詢
2025-11-12 08:17:23 +00:00
db.user_role.createIndex({"create_time": 1});