我正在将一些数据转储到我的MongoDb中,并在此过程中生成UUID。在集合中,这个UUID字段存储为LUUID(遗留UUID - 类型3),我不知道如何避免这种情况,因为我希望格式为标准UUID(类型4)。
实体:
@Document(collection = "sms")
public class SmsEntity {
...
private UUID ubmMessageSid; // <- this field gets stored as LUUID
...
public static class Builder {
...
private UUID ubmMessageSid;
...
public Builder ubmMessageSid(UUID ubmMessageSid) {
this.ubmMessageSid = ubmMessageSid;
return this;
}
public SmsEntity build() {return new SmsEntity(this);}
}
}
代码库:
@Repository
public interface SmsRepository extends CrudRepository<SmsEntity, String> {
}
存储此实体的服务:
...
var ubmId = UUID.randomUUID();
var smsEntity = SmsEntity.builder()
.ubmMessageSid(ubmId)
...
.build();
repository.save(smsEntity);
我需要注释或配置什么来将UUID存储为二进制/类型4吗?
return new MongoClient(...)
,而是需要使用return MongoClients.create(...);
,更多信息请参见此处。 - Zap