Doctrine MongoDb Embedded Document - How to specify fields Doctrine MongoDb Embedded Document - How to specify fields mongodb mongodb

Doctrine MongoDb Embedded Document - How to specify fields


The Specialization class uses a Document mapping, which is not intended for use with embedding. You should be using EmbeddedDocument for that.

Given that you want to use the same class on its own and in embedded form, it would be best to create an abstract class annotated with MappedSuperclass. There, you can define any field mappings that should exist on both the document and embedded document. In your case, you could leave visible to be defined on the inheriting document class.

Also, be aware that by using the set strategy, you're storing the embedded collection as an object instead of the usual array. This can have implications if you mean to index fields within the denormalized, embedded documents, as you won't be able to make use of multikey indexing. It's also possible to create gaps among the numeric keys.