// 1. 唯一索引:角色 UID 必須唯一 db.role.createIndex({"uid": 1}, {unique: true}); // 2. 複合唯一索引:同一個 Client 下角色名稱必須唯一 db.role.createIndex({"client_id": 1, "name": 1}, {unique: true}); // 3. 查詢索引:按 Client ID 查詢 db.role.createIndex({"client_id": 1}); // 4. 查詢索引:按狀態查詢 db.role.createIndex({"status": 1}); // 5. 複合索引:按 Client ID 和狀態查詢(常用組合) db.role.createIndex({"client_id": 1, "status": 1}); // 6. 時間戳索引:用於排序和時間範圍查詢 db.role.createIndex({"create_time": 1}); // 7. 時間戳索引:用於更新時間排序 db.role.createIndex({"update_time": -1});