I noticed FOSUserBundle does not create any indexes.
We are supposed to create a user Document like this:
use FOS\UserBundle\Document\User as BaseUser;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class User extends BaseUser
{
/**
* @MongoDB\Id(strategy="auto")
*/
protected $id;
/*
public function __construct()
{
parent::__construct();
// your own logic
}
*/
}
So how do I add an index to say, the ’email’ field? Should I just overwrite the inherited attribute?
Actually FOSUserBundle does create. You should run
to create them. By default there is usernameCanonical and emailCanonical indexes.
If you need custom index use this approach:
and do not forget to run doctirne:mongodb:schema:update task again.