question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use mongoose plugin based on pre with patch or put

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
dortamiguelcommented, Apr 10, 2017

I created a plugin that works with mongoose and feathers that solves this issue

https://github.com/ellipticaldoor/slugify-mongoose

0reactions
AdamGerthelcommented, Nov 14, 2020
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found