import Mongoose, {Schema} from 'mongoose'
import Timestamps from 'mongoose-timestamp'

let Post = new Schema({
  title: { type: String, index: true, required: true },
  slug: { type: String, index: true, required: true },
  image: { type: String },
  caption: { type: String },
  content: { type: String, required: true },
  tags: { type: Array, index: true }
})

Post.plugin(Timestamps)

export default Mongoose.model('Post', Post)

@@ -350,16 +350,29 @@
 ex: true
+, default: %5B%5D
  %7D%0A%7D)%0A%0AP
@@ -395,16 +395,272 @@
 tamps)%0A%0A
+Post.pre('save', function (next) %7B%0A  Mongoose.models%5B'Post'%5D.find(%7B%0A    slug: this.slug%0A  %7D, (err, results) =%3E %7B%0A    if (err) return next(new Error(err.message))%0A    if (results.length %3E 0) return next(new Error('Post already exists'))%0A    next()%0A  %7D)%0A%7D)%0A%0A
 export d

Add pre save function