Spaces:
Running
Running
| const mongoose = require('mongoose'); | |
| const errorLogSchema = new mongoose.Schema( | |
| { | |
| timestamp: { type: Date, default: Date.now, index: true }, | |
| type: { type: String, default: 'Error', trim: true }, | |
| message: { type: String, required: true, trim: true }, | |
| stack: { type: String, default: '' }, | |
| code: { type: String, default: 'INTERNAL_SERVER_ERROR', trim: true }, | |
| statusCode: { type: Number, default: 500 }, | |
| request: { | |
| url: { type: String, default: '' }, | |
| method: { type: String, default: '' }, | |
| ip: { type: String, default: '' }, | |
| userAgent: { type: String, default: '', maxlength: 300 }, | |
| bodyFields: { type: [String], default: [] }, | |
| }, | |
| userId: { type: String, default: '' }, | |
| env: { type: String, default: 'development' }, | |
| }, | |
| { versionKey: false } | |
| ); | |
| errorLogSchema.index({ timestamp: -1 }); | |
| errorLogSchema.index({ code: 1, timestamp: -1 }); | |
| module.exports = mongoose.model('ErrorLog', errorLogSchema); | |