code: function usernameIsUnique ( id ) {
          var deferred = q.defer();
  
          db.users.query( [ { key: 'identities.basic.username', cmp: '=', value: user.identities.basic.username } ] ,
              { limit: 1, skip: 0 } ).then(
                  function ( payload ) {
                      if ( payload.total === 0 ) {
                          deferred.resolve();
                      }
                      else if( !_.isUndefined( id ) && payload.results[0]._id.toString() === id.toString() ) {
                          deferred.resolve();
                      }
                      else {
                          deferred.reject( new Error(messages.duplicate_username) );
                      }
                  },
                  function ( err ) {
                      deferred.reject( err );
                  }
              );
  
          return deferred.promise;
      }
docs: /*
  If this is an 'insert' method and basic authentication is set. Then we need to make sure that only 1 username
  is allowed in our system.