We are currently in a c# environment and wondering if we can implement the uuidv7 format in mongodb and also get the benefit from it so not just have the same behavior as uuidv4.
There seem to be some way to do this:
- Use a GuidSerializer (representation v3) in pair with guid v7 generation library → We don’t know if we will benefit from the v7 with this
- Use as an object serializer ?
- Use it as string ?
What would be the best way to implement this? If it’s actually possible as today…
Welcome to the MongoDB Community Forums. I understand that you want to use UUIDv7 with the .NET/C# Driver.
Let’s start by talking about how UUID formats currently supported by the driver and MongoDB - UUIDv3 and UUIDv4. The main difference between UUIDv3 and UUIDv4 is that UUIDv4 specifies a consistent serialized byte ordering regardless of the language or endianness of your CPU whereas UUIDv3 does not. The main difference between UUIDv4 and UUIDv7 is the generation mechanism. Thus you could use UUIDv4 GUIDs in your application and register a new
IIdGenerator that uses the UUIDv7 generation mechanism. You could then register it via
BsonSerializer.RegisterIdGenerator(typeof(Guid), new UuidV7Generator()); wher
UuidV7Generator is your generator.
Hope that helps!