0

In my NextJS + MongoDB project, I have an API at api/groups/new.js that creates a new Group Object.

Is there a simple way to generate a unique slug parameter for each Group that's created based on the Group's name?

Allan
  • 2,586
  • 5
  • 26
  • 22
  • You mean you want to [generate a random string](https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript)? – juliomalves Mar 05 '21 at 18:44
  • @juliomalves no, more like converting a `name` of "Some Group Name" to "some-group-name" or "some-group-name-1" in the event of a naming conflict – Allan Mar 05 '21 at 19:02
  • 1
    I had that issue before, what I did is adding more field called nid based on unqiue random nano (small) id, it gonna be like this /[nid]/slug and this exactly what most websites use you can check this questions link above – Chemi Adel Mar 06 '21 at 01:49

0 Answers0