I have inheritance document with type SINGLE_COLLECTION
configured in my Symfony 4.4 app.
When i run command bin/console doctrine:mongodb:schema:create
, then error occurs a collection 'db.Person' already exists
.
Everything was done according to the documentation: https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.0/reference/inheritance-mapping.html#single-collection-inheritance
src/Document/Person.php
<?php
namespace App\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
* @MongoDB\InheritanceType("SINGLE_COLLECTION")
* @MongoDB\DiscriminatorField("type")
* @MongoDB\DiscriminatorMap({"person"=Person::class, "employee"=Employee::class})
*/
class Person
{
/**
* @var integer|null
*
* @MongoDB\Id
*/
protected $id;
/**
* @var string|null
*
* @MongoDB\Field(type="string")
*/
protected $name;
}
src/Document/Employee.php
<?php
namespace App\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Employee extends Person
{
/**
* @var string|null
*
* @MongoDB\Field(type="string")
*/
protected $grade;
}
It looks like command is trying to create DB collection for every Document class, ignoring declaration of SINGLE_COLLECTION type.
How to fix it?