Recommendations on GUID V3 when you have V2 data stored

If I understand it correctly the recommendations is to move to V3 as soon as possible.

What are then the recommendations for how to deal with old data in:

  1. Same application and same collection
  2. Same application but different collection

As the docs says that one application only can use either V2 or V3, are we then supposed to stop everything. Merge all data. And then have the application use the new format?

With lots of data, that’s not really an option. So are we then supposed to stay on V2? What happens when this gets deprecated?

Hey @Daniel_Wertheim,

It depends on what guid represention you have now in your data and what guid representation you want to see your data in after. If all your Guids are currently in CSharpLegacy representation then the following might suffice:

BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));

That would switch them to V3 mode while keeping all the Guids in CSharpLegacy representation.

It’s worth mentioning that those two lines have to execute before any database operations so that they take effect before any class auto-mapping takes place. They should be some of the first lines executed.

If you also want to convert all your existing data to GuidRepresentation.Standard then you need to go offline and convert your data.

Hi, thanks for the reply.

Basically, you can not mix and match in one application (need to be different processes due to static conf) then. Why couldn’t this be controlled on a per-class-map basis? At least, e.g. the registration of the GuidSerializer.

Lets say you have one collection “lab-doc” which contains docs with IDs stored using current defaults (meaning V2 and CSharpLegacy)

If we then were able to use:

BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;

but per class register the serializer:

BsonClassMap.RegisterClassMap<LabDocObsolete>(cm =>
{
    cm.AutoMap();
    cm
        .MapIdMember(i => i.Id)
        .SetSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy));
});

BsonClassMap.RegisterClassMap<LabDoc>(cm =>
{
    cm.AutoMap();
    cm
        .MapIdMember(i => i.Id)
        .SetSerializer(new GuidSerializer(GuidRepresentation.Standard));
});

we could in one app use LabDocObsolete against e.g. lab-doc and use LabDoc against collection lab-doc-something.