Open anas10 opened 8 years ago
Hi anans10. I have not touched mongoose for a while, but I think it is possible following this. It is written by icedcoffeescript.
slug = require 'mongoose-friendly-id'
schema.plugin slug, (model) ->
slugged = "#{model.name}--#{model.job}"
await schema. findByFriendlyId slugged, defer(err, user)
if user
"#{slugged}-#{model.id}"
else
slugged
Is it possible to handle the case where a slug already exists and generate a unique slug by adding a number at the end for example ?
The friendly slug is very handy but not unique.