Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Change Mongoose unique to boolean #521

Closed
wants to merge 1 commit into from
Closed

Conversation

simison
Copy link
Member

@simison simison commented Apr 19, 2015

@ilanbiala
Copy link
Member

Was that changed in Mongoose 4.0? Is there a way to make sure these are the 3.8 docs?

@simison
Copy link
Member Author

simison commented Apr 19, 2015

Nope, it was boolean also with 3.x: http://mongoosejs.com/docs/3.8.x/docs/api.html#schematype_SchemaType-unique
Not sure when it has changed, if ever; http://mongoosejs.com/docs/prior.html

The irritating bit is that currently at signup controller, Mean.js doesn't shout out if it's the email that's unique or the username. It just shouts "Unique field already exist", which isn't very helpful for the user.

Mongoose-unique-validator tries to solve the issue, but I don't know if that's a great package.

@ilanbiala
Copy link
Member

@lirantal thoughts on why it was a string?

@lirantal
Copy link
Member

I don't recall on why this was set as string, but it seems a reasonable fix to update to boolean so I'll merge if it LTY

@lirantal lirantal assigned lirantal and ilanbiala and unassigned lirantal Apr 29, 2015
@ilanbiala
Copy link
Member

Lgtm.

@simison
Copy link
Member Author

simison commented May 28, 2015

Volá, now someone made a plugin that adds support to unique: 'Error message' -format. I might add this first to my project and then update this PL.

Read more: Automattic/mongoose#2284 (comment)

Plugin: https://www.npmjs.com/package/mongoose-beautiful-unique-validation

@codydaig
Copy link
Member

codydaig commented Aug 2, 2015

@simison Is this something that still needs to get changed in the 0.4 version? Or are we leaving it as a string to represent the error message?

@lirantal
Copy link
Member

lirantal commented Aug 2, 2015

@simison is that a bug though? it does work today because there's a validation attached to that specific field. Correct me if I'm wrong.

@simison
Copy link
Member Author

simison commented Aug 5, 2015

I think it "works" now with a string because it returns true, but it doesn't work as expected since that message won't be sent with the error. I recently implemented a solution elsewhere with that mongoose-beautiful-unique-validation package so I think I could send a PL a bit later.

Let's leave the string there for now and it'll then just work with mongoose-beautiful-unique-validation. Closing this.

@simison simison closed this Aug 5, 2015
@ilanbiala
Copy link
Member

@simison I think we may also run into some issues when we upgrade to Mongoose Mongoose 4.1.x, which would definitely be awesome when we start using promises instead of callbacks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants