title: How to generate a slug everytime an article is created and saved in the database?
body: <p>So, I have this <strong>articleSchema</strong> in which I want to create a unique slug.</p>
  
  <pre><code>const mongoose = require("mongoose")
  const Schema = mongoose.Schema
  var URLSlug = require('mongoose-slug-generator')
  
  const articleSchema = new Schema({
      title: { type: String, required: true },
      description: { type: String, required: true },
      userId: { type: Schema.Types.ObjectId, ref: "User" },
      slug: { type: "String", slug: "title", unique: true }
  }, { timestamps: true })
  
  
  articleSchema.pre("save", function(next) {
      this.slug = this.title.split(" ").join("-")
      next()
  })
  
  articleSchema.plugin(URLSlug("title", {field: "Slug"}))
  
  const Article = mongoose.model("Article", articleSchema)
  
  module.exports = Article
  </code></pre>
  
  <p>Here is the <strong>articleController</strong></p>
  
  <pre><code>    newArticle: (req, res) =&gt; {
          Article.create(req.body, (err, newArticle) =&gt; {
              if (err) {
                  return res.status(404).json({ error: "No article found" })
              } else {
                  return res.status(200).json({ article: newArticle })
              }
          })
      }
  </code></pre>
  
  <p>I don't know, when I check this in postman it's saying no article found, let alone the slug! Also, I'm getting this error:</p>
  
  <p><code>schema.eachPath is not a function</code></p>