Spaces:
Running
Running
| const mongoose = require('mongoose'); | |
| const accessSessionSchema = new mongoose.Schema({ | |
| email: { type: String, index: true }, | |
| role: { type: String, enum: ['student', 'instructor', 'admin', 'visitor'], index: true }, | |
| startAt: { type: Date, default: Date.now, index: true }, | |
| lastSeen: { type: Date, default: Date.now, index: true }, | |
| userAgent: { type: String }, | |
| ip: { type: String }, | |
| path: { type: String } | |
| }, { timestamps: true }); | |
| // Compound index for querying active sessions by email + startAt | |
| accessSessionSchema.index({ email: 1, startAt: -1 }); | |
| module.exports = mongoose.model('AccessSession', accessSessionSchema); | |