New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Docs] Contradiction in docs/middleware.md #12113
Comments
Additionally, the unordered lists in Types of Middleware could have titles for clarity. For example: Types of MiddlewareMongoose has 4 types of middleware: document middleware, model middleware, aggregate middleware, and query middleware. Document middleware is supported for the following document functions. In document middleware functions, this refers to the document. Document:
|
How exactly does the section you linked to "shows that save middleware is supported for Model"? Document middleware = middleware for documents (which are instances of Models). Model middleware = middleware for static functions on models, like |
I misunderstood the unique terms that mongo uses. The following expression snippet makes a Document, but I thought it was a Model because it is an instance of a Model. new User({ name: 'test' }) I was confused because "documents represent a one-to-one mapping to documents as stored in MongoDB" so I assumed that a model created, but not yet saved was just a Model instance, but not a Document yet. |
So I guess there isn't a contradiction in docs/middleware.md, but perhaps the sentence quoted from docs/documents.md could be updated to clarify that documents not a one-to-one mapping to documents as stored in MongoDB, as they can be created and not saved. |
That's fair. I think it's worth clarifying a little bit the difference between models and documents in the middleware docs. |
Prerequisites
Issue
Here's the page.
I ran into this issue while trying to use
pre
/post
middleware withModel.save()
.According to the top of the doc,
save
middleware is only supported for theDocument
class.However, the section Define Middleware Before Compiling Models shows that
save
middleware is supported forModel
.The code snippets in the section don't work for me, but
save
should be a basic supported feature. For example, pre middleware tosave
a user can encrypt a password.The text was updated successfully, but these errors were encountered: