KPJS/blog

make posts title uniqueue

Closed this issue · 1 comments

yohny commented

in current proposed implementation (#38) we use post title as URI, so to prevent more posts having same URI we need to make it uniqueue
alternative: add uniqueue property uri that contains user-friendly URI for given post

New uri field has been added to posts collection.
Unique index has been created for uri field.

Used command:
db.posts.update({_id:ObjectId("56325baee9f8eb1f18679405")}, {$set:{uri:"ssh-git-deployment"}})

Used command:
db.posts.createIndex({uri:1}, {unique:true})

Response:
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}

Check commnad:
db.posts.find({},{title:1,uri:1,_id:0}).sort({publishDate:1})