Search code examples
mongodbmongoosemongodb-queryslug

Why to use slug field in mongodb document?


I tried to create category hierarchy.So,I refer this link (https://docs.mongodb.com/ecosystem/use-cases/category-hierarchy/) link given number example how to create category hierarchy .but I have a doubt I this example is used slug field.why to use slug I could not understand can you please give solution.

Example Document

{ "_id" : ObjectId("4f5ec858eb03303a11000002"),
  "name" : "Modal Jazz",
  "parent" : ObjectId("4f5ec858eb03303a11000001"),
  "slug" : "modal-jazz",
  "ancestors" : [
         { "_id" : ObjectId("4f5ec858eb03303a11000001"),
        "slug" : "bop",
        "name" : "Bop" },
         { "_id" : ObjectId("4f5ec858eb03303a11000000"),
           "slug" : "ragtime",
           "name" : "Ragtime" } ]
}
  • what is slug ?
  • Which purpose using in document ?
  • why to use slug field ?

Solution

  • Slug field is URL shortcut to get document or sub/document is simple way. Slug is used in document to make easy get document from URL

    For example, typing http://**host**/modal-jazz you should get document that has "modal-jazz" as 'slug'.

    I hope i helped you a bit.