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

22 lines
762 B
Plaintext

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