I have an account document that looks like this:
_id: ###
email: string
password: md5(string)
altemail: [{ email: string
verified: time},
{ email: string
verified: time},
{ ... }]
And i would like to check for unique email before allowing a user to create an account. However, i would also like to permit saves for the current user _id.
My instinct is to use:
$db->users->find(array(
'$or' => array(array("email" => $email),
array("altemail.email" => $email))
'_id' => array('$nin' => array($myID))
));
But this isn't working for me. Could somebody show me how to set up a query roughly equivalent to mysql's:
SELECT *, count(_id) FROM users WHERE (email = $email OR altemail.email = $email) AND (_id != $myID);
Thanks guys.