Mongoose Yet Another Slug
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
README.md
index.js
package.json
yarn.lock

README.md

npm (scoped) Build Status

mongoose-yas

Mongoose Yet Another Slug, follows the same idea to create a slug based on meteor-friendly-slugs. This package uses same API and data structure:

{
  slug: 'your-slug', // Actual slug can be used in your app
  friendSlugs: { // Should be used by the plugin only
    slug: {
      base: 'your-slug', // Slug result from `slugFrom` without index
      index: 0, // Index of `slug` that is in the same `base`
    }
  }
}

Usage

const mongoose = require('mongoose')
const mongooseyas = require('@pozible/mongoose-yas')

const Schema = new mongoose.Schema({
  title: {type: String},
  friendlySlugs: Object,
  publisher: {type: String},
  slug: {type: String, slugFrom: 'title', distinctUpTo: ['publisher']},
})

Schema.plugin(mongooseyas)

const Book = mongoose.model('Book', Schema)

Book.create({
  title: 'i ♥ unicode',
  publisher: 'PUB_1'
}, function(book) {
  console.log(book.slug)
})

Important: slug and friendlySlugs are required attributes that must be declared in schema.

Limitations

  • Fixed slug and friendlySlugs attributes that must be declared in schema to make the plugin works.
  • and few other more.