mongo document index annotation doesnt work

300 Views Asked by At

why the index creation (properthy testId) doesnt work? I've tried it via annotation. Can somebody help in this case?

 /**
 * @ODM\Field(type="string")
 * @ODM\Index(unique=true, order="asc")
 * @Assert\NotBlank
 * @Assert\Type(
 *     type="string",
 *     message="The value {{ value }} is not a valid {{ type }}."
 * )
 */
public $testId;
1

There are 1 best solutions below

1
On

Annotation just lets ODM know that you want an index, you need to actually create it. By @Assert usage I assume you're a Symfony user, so just run ./bin/console odm:schema:create --index

Full docs on indexes can be found here: https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.1/reference/indexes.html