DEV Community

leran500
leran500

Posted on

mongoose v7 pre hook error

i am using Mongoose v7.x in my nestJS projec, i want to use pre hook with where condition like this:

const schema = JsonSchemaSchema;
      //Pre middleware will apply on any Query middleware that start with find or update or delete)
      schema.pre(new RegExp('(find|update|delete)'), function () {
        this.where({
          ...buildNotDeletedCondition(),
          ...authorizationService.buildEntitiesAuthCondition(),
        });
      });
Enter fullscreen mode Exit fullscreen mode

but i am geeting the following error:
` Property 'where' does not exist on type '(Document> & Omit & Required<{ _id: ObjectId; }>, never>) | Query<...>'. Did you mean '$where'?
Property 'where' does not exist on type 'Document> & Omit & Required<{ _id: ObjectId; }>, never>'.

12 this.where({
~~~~~

`

my code work fine in mongoose v6. anyone know how i could solve this?

Top comments (0)