I have a beta signup form, I need to know how do I check to make sure the email address is not already in the database, and if it is not add it, if it is return a message.
I am hoping I don’t have to do a find and then an if and then an insert, but something tells me I will have to.
You can create a unique index on email and then perform an insert in safe mode. If email is taken, you’ll get an error. You won’t get this error if there’s no unique index or operation is not in safe mode.
I personally would do a simple
find. For example, on this signup form when user entered his email and moves to the next field, I’d fire a quick ajax request to the server and find out if this email is taken or not and display result of this check in the form. This, of course, does not replace the need for unique index and safe mode (google race conditions).