Mongodb mongo文档索引注释不起作用

Mongodb mongo文档索引注释不起作用,mongodb,annotations,doctrine,doctrine-odm,Mongodb,Annotations,Doctrine,Doctrine Odm,为什么索引创建(properthytestid)不起作用?我试过通过注释。有人能帮忙吗 /** * @ODM\Field(type="string") * @ODM\Index(unique=true, order="asc") * @Assert\NotBlank * @Assert\Type( * type="string", * message="The value {{ value }}

为什么索引创建(properthytestid)不起作用?我试过通过注释。有人能帮忙吗

 /**
 * @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;

注释只是让ODM知道您想要一个索引,您需要实际创建它。通过
@Assert
用法,我假设您是一个Symfony用户,所以只需运行
/bin/console-odm:schema:create--index


有关索引的完整文档可在此处找到:

首先,您是否能够连接并将数据插入mongo collections?是的,我还有一个自动增量id,这很有效谢谢您的回复。遗憾的是,控制台命令不起作用。错误:“odm:schema”命名空间中未定义任何命令。你是说其中一个吗?api:json模式条令:模式orm:convert