Doctrine - MongoDB, id from type BinData
-
21-12-2019 - |
Question
I have MongoDB data which uses _id
as BinData
object.
{
"_id" : BinData(3,"ABRWTIFGPEeSFf69fISAOA=="),
"Email" : "XXXXX@msn.com",
}
How to set annotation mapping for _id
from type BinData
?
Solution 2
after #444 merged into master ,we can deal with BinData Obejct
into MongoDB
as MongoBinData Object
with same type \MongoBinData::UUID
(3)
Annotation we must use int this case when we use Doctrine MongoDB ODM is @Id(type="bin_uuid")
OTHER TIPS
MongoDB's BinData is backed by the PHP Class MongoBinData.
The Doctrine documentation at http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/annotations-reference.html#bin says that you can use the @Bin
annotation, or other annotations starting with @Bin
.
Following http://bsonspec.org/#/specification, the binary subtype "3" is "UUID (Old)" which is deprecated in favour of type 4
(UUID). I think you should be able to use @BinUUID
for this type for which http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/annotations-reference.html#binuuid has the documentation.