talha-asad / mongoose-url-slugs

Create URL compatiable slugs on mongoose models, ensuring uniqueness.
MIT License
40 stars 22 forks source link

TypeError: Cannot read property `indexOf` of undefined #52

Open nimatrazmjo opened 3 years ago

nimatrazmjo commented 3 years ago

Monoose version:

"mongoose": "^5.9.25",

When I want to enable update in slug generation it returns bellow error:

Screen Shot 2021-02-23 at 3 03 25 PM

Before this, it was working, but now have the above issue

razmjo-netlinks commented 3 years ago

@talha-asad need your help please

nimatrazmjo commented 3 years ago

It works fine if I downgrade my mongoose npm version to 5.8.11

Vednus commented 8 months ago

This is a small bug in this package where slugField should be slugFields. Below is the patch

diff --git a/node_modules/mongoose-url-slugs/index.js b/node_modules/mongoose-url-slugs/index.js
index 5e560ac..9eba3ec 100644
--- a/node_modules/mongoose-url-slugs/index.js
+++ b/node_modules/mongoose-url-slugs/index.js
@@ -212,7 +212,7 @@ module.exports = function(slugFields, options) {
         if (toSlugify.length) toSlugify = toSlugify.substr(0, toSlugify.length - 1);
         else toSlugify = options.undefinedVal;
       } else {
-        if (!doc.isSelected(slugField)) slugFieldsSelected = false;
+        if (!doc.isSelected(slugFields)) slugFieldsSelected = false;
         if (doc.isModified(slugFields)) slugFieldsModified = true;
         var slugPart = doc.get(slugFields, String);
         if (slugPart !== undefined) toSlugify += slugPart;
Vednus commented 8 months ago

It was actually fixed here: https://github.com/talha-asad/mongoose-url-slugs/pull/51, but a new package was never created on npm.