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?

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay