在猫鼬模式中获取请求?

问题描述 投票:0回答:0

所以我正在尝试对我的 mongodb 模式进行全局查询,这是我到目前为止所做的

const globalPlugin = (schema) => {

    schema.pre('find', function () {
        this.where({
            deleted_at: {
                $exists: false
            }
        });
    });

    schema.pre('findOne', function () {
        this.where({
            deleted_at: {
                $exists: false
            }
        });
    });

    schema.pre('findOneAndUpdate', function () {
        this.where({
            deleted_at: {
                $exists: false
            }
        });
    });
};

module.exports = globalPlugin;

但是我需要的是从身体传递“请求”的东西,因为我想用像这样的子域做一些事情

this.where({
   deleted_at: {
      $exists: false
   },
   tenant_id: req.subdomains[req.subdomains.length - 1]
});

有什么办法可以做到这一点?非常感谢!

node.js mongoose schema
© www.soinside.com 2019 - 2024. All rights reserved.