Attributes Reference

Doctrine Annotations are deprecated and replaced by native PHP attributes. All the attributes listed on Attributes Reference can be used as annotations.

Support for annotations will be removed in Doctrine MongoDB ODM 3.0.

If you are still using annotations, you can migrate your code to attributes by following the guide below:

Change the metadata driver configuration to use the AttributeDriver:

1- use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationsDriver; + use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver; - $config->setMetadataDriverImpl(AnnotationsDriver::create(__DIR__ . '/Documents')); + $config->setMetadataDriverImpl(AttributeDriver::create(__DIR__ . '/Documents'));
2
3
4
5

Replace the @ORM\Document annotations with the #[ORM\Document] attribute.

1use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; - /** - * @ODM\Document - */ + #[ORM\Document] class User { - /** - * @ORM\Id - */ + #[ORM\Id] public string $id; - /** - * @ORM\Column(type="string") - */ + #[ORM\Column(type: "string")] public string $name; }
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

You can use Rector to automate the migration process. See How to Upgrade Annotations to Attributes for more information.