Reputation: 1171
I need to create SEO friendly URLs with Node.js, but before inserting document I'd like to check if there is already some other document which has url like that. I was searching for some module which could transform string to URL, but I found only one https://github.com/ludopoli/friendlyjs. Is there any other module which can do that and it has created interaction with Mongoose, so it checks for before created URLs?
Upvotes: 3
Views: 2658
Reputation: 14953
I solved this problem myself quite recently, and your post made me feel like I should turn it into a module and publish it. I called it monguurl. Basically it hooks in before save, converts a specified field to a url-friendly string, checks if it's not taken already and if it is, appends a number.
Upvotes: 3
Reputation: 63159
You could ensure unique names on the database level. MongoDB has an unique index type. This way no name (or whatever) could be used twice.
Upvotes: 0