Update: Now official support for this type. Use @ObjectId or @Field(type="object_id") in your annotation to use the ObjectId / MongoId type. No need to use the solution below.
Also, use the latest master code from github.com/doctrine/mongodb-odm and do not use the version on the website (this is deprecated).
Solution (deprecated)
There seems to be no support yet. I discussed this issue on the IRC channel and opened a ticket for him: https://github.com/doctrine/mongodb-odm/issues/125
A temporary fix will be to define a custom type and use annotation like @Field(type="objectid") in the document classes.
Here is the code for the custom type that I use to execute this.
class ObjectId extends \Doctrine\ODM\MongoDB\Mapping\Types\Type { public function convertToDatabaseValue($value) { if ($value === null) { return null; } if ( ! $value instanceof \MongoId) { $value = new \MongoId($value); } return $value; } public function convertToPHPValue($value) { return $value !== null ? (string)$value : null; } }
Register it using
\Doctrine\ODM\MongoDB\Mapping\Types\Type::addType('objectid', 'ObjectId' );
source share