Can't use mongoose plugin based on pre with patch or put
See original GitHub issueI’m using this plugin for generating an slug https://github.com/mindblaze/mongoose-url-slugs (I also tried 10 different plugins with the same result)
I have this when I do a “get” to http://localhost:3030/posts/58e77fb2bdce58efa796f183
{
"_id": "58e77fb2bdce58efa796f183",
"description": "A description for the First Post",
"title": "First Post",
"createdAt": "2017-04-07T12:01:54.976Z",
"slug": "first-post"
}
If I do a “put” (update in hooks) to the same url with this fields:
{
"title": "new title",
"description" : "new description"
}
I get this response:
{
"_id": "58e77fb2bdce58efa796f183",
"title": "new title",
"description": "new description"
}
“createdAt” and “slug” disappeared, of course with “patch” this doesn’t happens but then I can’t generate my slug. 😕
How I can solve this? Should be good to force an update to patch? This can be possible?
I think the problem is that path is not calling the mongoose event ‘validate’
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
mongoose changing update on pre('update') does not work on ...
My Code below contains the schema and a pre('update') middleware to manipulate the name property of the schema. Actually I just want to...
Read more >Mongoose v6.8.2: Plugins
Plugins are a tool for reusing logic in multiple schemas. Suppose you have several models in your database and want to add a...
Read more >Does MongoDB still update or overwrite a document if the ...
Yes @scott_molinari, In mongoDB if we update the records using updateMany clause it ... Mongoose has a pre hook available to add timestamps....
Read more >Mongoose - npm
Mongoose MongoDB ODM. Latest version: 6.8.2, last published: 4 days ago. Start using mongoose in your project by running `npm i mongoose`.
Read more >mongoose | Yarn - Package Manager
Mongoose is a MongoDB object modeling tool designed to work in an ... fix(discriminator): apply built-in plugins to discriminator schema even if mergeHooks ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I created a plugin that works with mongoose and feathers that solves this issue
https://github.com/ellipticaldoor/slugify-mongoose
I have the exact same problem, see https://github.com/feathersjs-ecosystem/feathers-mongoose/issues/395