Closed randrewy closed 1 year ago
What is the current represenation?
Currently it is stored as string like .ToString
was called on guid object: "db331560-56c6-4a35-84cc-1846d0d5cc7e"
This library does not use mongo serializer. It uses Newtonsoft.JSON and then converts it to BSON. So you can write your own serializer if you need another representation. But binary data is not supported.
Actually I can write custom converter to store Guid as binary data, but that means I have to
.ToByteArray()
)I've looked through the code and found this converter you are talking about and there is this special case for Guid
type
https://github.com/OrleansContrib/Orleans.Providers.MongoDB/blob/22bc56b54b9407453116d9f2294700e40992bdb4/Orleans.Providers.MongoDB/StorageProviders/JsonBsonConverter.cs#L79-L80
I can confirm that Newtonsoft.Json library recognize guids and serialize them with proper JTokenType.Guid
MongoDb Driver has it's own converter in form of Implicit Conversion (Guid to BsonValue) and it should tolerate at least global BsonDefaults.GuidRepresentation
settings (I've never checked that).
Edit: implicit conversion is deprecated and BsonBinaryData(Guid guid, GuidRepresentation representation)
should be used.
So it looks like there is everything needed to implement this feature. The only remaining questions are: is is it planned for implementation? PR are welcomed?
I do not see that much benefit in a byte representation. It is so much harder to debug.
But you are welcome to provide a PR, but it must be backwards compatible. BsonDefaults.GuidRepresentation
is therefore not an option.
I see 2 options:
Is this something you want to work on or can we close the issue?
There is a way to set guid db representation using C# MongoDb client using GuidSerializer Is there anything like that option in MongoDB Storage Provider? Any plans to add it in future?
I've tried both
[BsonGuidRepresentation(GuidRepresentation.Standard)]
annotation on myGuid
field and globalBsonDefaults.GuidRepresentation = GuidRepresentation.Standard;
setting, but neither of them worked for me.