8 works

Slugify a Field in Mongoose Schema


dashboard+ Project

Posted by @mishka #javascript #nodejs

Code snippet:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var slug = require('mongoose-slug-generator');

mongoose.plugin(slug);

const pageSchema = new Schema({
    title: { type: String , required: true},
    slug: { type: String, slug: "title" }
});

var Page = mongoose.model('Page', pageSchema);
module.exports = Page;
content_copyCopy to Clipboard

More details:

First install express package: mongoose-slug-generator npm install mongoose-url-slugs


>> Browse more code snippets

more_vert