Javascript 我想访问mongoose和schema中的请求信息

Javascript 我想访问mongoose和schema中的请求信息,javascript,node.js,mongoose,Javascript,Node.js,Mongoose,我想访问nodejs和mongoose模式中的请求信息 我有一个BaseSchema: export function BaseSchema(schema) { schema.add({ isDelete: { type: Boolean, default: false }, owner: { type: String }, updateDate: { type: String }, updateBy: { type: String }, delete

我想访问nodejs和mongoose模式中的请求信息

我有一个
BaseSchema

export function BaseSchema(schema) {
  schema.add({
    isDelete: { type: Boolean, default: false },
    owner: { type: String },
    updateDate: { type: String },
    updateBy: { type: String },
    deleteDate: { type: String },
    deleteby: { type: String },
    createDate: { type: String },
    createBy: { type: String },
  });

  schema.pre("save",async function (req, res, next) {
  console.log("BaseSchema -> req",await req)
    if (!schema.isNew) {
      this.createDate = new Date();
      this.createBy = `${req.user.firstName} ${req.user.lastName}`;
    }
    next();
  });
主要通过以下方式使用:

export default interface Category extends Document {
    name: string;
    icon: string;
    parentId: string;
}

const CategorySchema = new Schema({
    name: { type: String, require: true },
    icon: { type: String, require: true },
    parentId: { type: String },
}, {
    toJSON: { virtuals: true }
});

CategorySchema.plugin(BaseSchema);

export const CategoryModel = model<Category>("Category", CategorySchema)
导出默认接口类别扩展文档{
名称:字符串;
图标:字符串;
parentId:string;
}
const CategorySchema=新模式({
名称:{type:String,require:true},
图标:{type:String,require:true},
parentId:{type:String},
}, {
toJSON:{virtuals:true}
});
插件(BaseSchema);
导出常量CategoryModel=模型(“类别”,CategorySchema)
但是在
BaseSchema
中,它向我显示了这个=>
req[函数(匿名)]


现在我如何访问
请求
信息???

我不清楚你在问什么或者你有什么具体问题。您似乎不希望“访问模型中的请求”,而是希望将请求信息存储为模型数据的一部分。你是说你不能这么做吗?@DaveNewton是的。我想访问请求中用户的名字和姓氏