const mongoose = require('mongoose'); const RolePermSchema = new mongoose.Schema({ role: { type: mongoose.Schema.Types.ObjectId, ref: 'Role', required: true }, permission: { type: mongoose.Schema.Types.ObjectId, ref: 'Permission', required: true } }, { timestamps: true }); // 索引 RolePermSchema.index({ role: 1, permission: 1 }, { unique: true }); RolePermSchema.index({ role: 1 }); RolePermSchema.index({ permission: 1 }); module.exports = mongoose.model('RolePerm', RolePermSchema);