I'm using MongoDB with Doctrine for a Symfony project.
For a document (I call it class Product
) I need to define a field (e.g. name), but I want to act doctrine in a way that the document cannot be saved without defining a it. Meaning, whenever creating or updating a new Product, the property $name
has to be defined.
For doctrine and MySql this is quite simple. There you have to say:
class Product {
...
/** @ORM\Column(type="string", nullable=false) */
private $name;
...
}
Is there a similar way in MongoDb?
The following code (which I found in a similar thread) doesn't work:
class Product {
...
/**
* @MongoDB\Field(type="string")
* @Constraints\NotBlank
*/
protected $name;
...
}