Skip to content
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

TypeError: Cannot read property indexOf of undefined #52

Open
nimatrazmjo opened this issue Feb 23, 2021 · 4 comments
Open

TypeError: Cannot read property indexOf of undefined #52

nimatrazmjo opened this issue Feb 23, 2021 · 4 comments

Comments

@nimatrazmjo
Copy link

nimatrazmjo commented Feb 23, 2021

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
Copy link

@talha-asad need your help please

@nimatrazmjo nimatrazmjo changed the title Slug generation is not working when using {update: true} TypeError: Cannot read property indexOf of undefined Mar 2, 2021
@nimatrazmjo
Copy link
Author

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

@Vednus
Copy link

Vednus commented Nov 24, 2023

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
Copy link

Vednus commented Nov 24, 2023

It was actually fixed here: #51, but a new package was never created on npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants