You are trying to create two users with the same email address after defining the email as a unique field.
Perhaps you can request the user at this email address - if he already exists - return an error or update this user.
var params = {email: ' email@email.com '}; User.findOne(params).done(function(error, user) { // DB error if (error) { return res.send(error, 500); } // Users exists if (user && user.length) { // Return validation error here return res.send({error: 'User with that email already exists'}, 403.9); } // User doesnt exist with that email User.create(params).done(function(error, user) { // DB error if (error) { return res.send(error, 500); } // New user creation was successful return res.json(user); }); });
Sails.js and MongoDB: duplicate key error index
There is also an interesting bit about the unique properties of the model in the Sails.js docs https://github.com/balderdashy/waterline#indexing
EDIT: Pulled from http://sailsjs.org/#!documentation/models
Available checks:
empty, required, notEmpty, undefined, string, alpha, numeric, alphanumeric, email, url, urlish, ip, ipv4, ipv6, creditcard, uuid, uuidv3, uuidv4, int, integer, number, final, decimal, float , falsey, truey, null, notNull, boolean, array, date, hexadecimal, hexColor, lowercase, uppercase, after, before, is, regex, not, notRegex, equals, contains, notContains, len, in, notIn, max, min , minLength, maxLength