ahmed hamdy
ahmed hamdy

Reputation: 5169

Doctrine - MongoDB, id from type BinData

I have MongoDB data which uses _id as BinData object.

{  
   "_id" : BinData(3,"ABRWTIFGPEeSFf69fISAOA=="),
   "Email" : "[email protected]", 
}

How to set annotation mapping for _id from type BinData?

Upvotes: 0

Views: 911

Answers (2)

ahmed hamdy
ahmed hamdy

Reputation: 5169

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")

Upvotes: 0

Derick
Derick

Reputation: 36784

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.

Upvotes: 1

Related Questions