title: How to create Unique constraint object for form validation?
body: <p>I need to add the constraints on the fly in the controller action, so I'm doing this:</p>
  
  <pre><code>use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique;
  
  // ...
  
      $form = $this-&gt;createFormBuilder($user)
          -&gt;add('email', 'email', array(
              'constraints' =&gt; array(
                  new NotBlank(),
                  new MinLength(8),
                  new MaxLength(100),
                  new Email(),
                  new Unique(),
              ),
          ))
          -&gt;getForm();
  </code></pre>
  
  <p>But I get this error:</p>
  
  <p><code>The options "fields" must be set for constraint Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique</code></p>
  
  <p>I tried passing an <code>array('fields' =&gt; 'email')</code> and <code>array('fields' =&gt; array('email'))</code> to the constructor but didn't work: <code>Warning: get_class() expects parameter 1 to be object, string given in /home/www/dev/public/pixfeed/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php line 63</code></p>
  
  <p>So how do I use this class?</p>