Skip to content

bug in pre save hook for Place schema #1

@shonihei

Description

@shonihei

when creating a new place document, the pre hook attempts to come up with a new unique slug that can be used as part of a URL. Here's one way to screw that up:

  1. Create a new place with a name of 'abc'. Slug for it will be 'abc'
  2. Create another place with the same name of 'abc'. Slug for it will be 'abc-2'
  3. Create another place with the name of 'abc-3'. Slug for it will be 'abc-3'
  4. Create another place with the name of 'abc' again. Slug will be 'abc-3'

In step 4, mongoose will throw its hands up in the air and give up on everything because 'abc-3' as a slug already exists. I don't know what's the best way to fix this issue besides using a while loop to keep checking if a potential slug is valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions