mongodb-odm: Indexes missing / Single Collection Inheritance

Hi all,

I’m doing Single Collection Inheritance like this :

 @MongoDB\Document(
      collection="baseobjects",
      repositoryClass="PUC\CommonBundle\Repository\BaseObjectRepository",
      indexes={
         @MongoDB\Index(keys={"type"="asc"}),
      },
      requireIndexes=true
 )
 @MongoDB\InheritanceType("SINGLE_COLLECTION")
 @MongoDB\DiscriminatorField(fieldName="type")
 @MongoDB\DiscriminatorMap({
      "child" = "Child",
      ...
 })

class BaseObject
...


 @MongoDB\Document(
      collection="child",
      repositoryClass="PUC\CommonBundle\Repository\ChildRepository",
      indexes={
         @MongoDB\Index(keys={"email"="asc"})         
      },
      requireIndexes=true
 )

class Child extends BaseObject
...

Child indexes are not generated at BaseObject level (since Mongo 2.2.2) when using doctrine:mongodb:schema:update/create command.

Since I require Indexes when querying Child objects (requireIndexes=true) it triggers an error : “Cannot execute unindexed queries on TEST\MyBundle\Document\Child. Unindexed fields: email”

I noticed that children collections are not physically created anymore in db since 2.2.2, which seems fair, but then the indexes shall be on mother class (which is stored), isn’t it ? If I create one manually on mother class it works fine.

Thanks you for your feedback,

Cheers

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@getvivekv nobody stops you from doing so