Skip to content

hook is not of type Query #7790

@frederik-b

Description

@frederik-b

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
this context in hooks are not of type Query anymore

If the current behavior is a bug, please provide the steps to reproduce.

query hook:

mySchema.pre('findOneAndUpdate', async function setDefaultOptions(this: any) {
  console.log(this instanceof Query) // false, used to be true up to mongoose 5.4.22
})

call findOneAndUpdate

await model(message.messageType).findOneAndUpdate({_id: {$exists: false}}, newMessage, {upsert: true})

What is the expected behavior?

behaviour should not change between minor versions of mongoose
query hooks should be of type Query

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose 5.5.6 is broken (and earlier)
mongoose 5.4.22 is the last tested working version

# mongod --version                       
db version v4.0.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions