Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Friendly URLs for your Mongoose models
JavaScript
branch: master

Merge pull request #2 from kwhitley/master

update option to allow friendly field to update on subsequent saves
latest commit aea8b9602c
@gtramontina authored

README.md

mongoose-friendly

Build Status Dependency Status NPM version

Friendly URLs for you Mongoose models.

Usage

Simply install the mongoose-friendly plugin in your schema like this:

var mongoose = require('mongoose');
var friendly = require('mongoose-friendly');
var MySchema = new mongoose.Schema({ title: String });
MySchema.plugin(friendly);

A static method findByFriendly is added to your schema, and you can use it as if you were using findById.

Here are the options (as defaults) you can pass when installing the plugin:

MySchema.plugin(friendly, {
  source: 'title',  // Attribute to generate the friendly version from.
  friendly: 'slug', // Attribute to set the friendly version of source.
  update: false,    // Updates friendly field on subsequent saves.
  addIndex: true,   // Sets {unique: true} as index for the friendly attribute.
  findById: true    // Turns findById into an alias for findByFriendly.
});

License

This is licensed under the feel-free-to-do-whatever-you-want-to-do license.

Something went wrong with that request. Please try again.