Mongo DB C# API,将 GUID 转换为 LUUID 而不是 UUID

问题描述 投票:0回答:1

我有一个 C# MongoDB 驱动程序 2.15.0,它使用 Modals 将数据插入到 MongoDB。但在我的测试环境中,插入 MongoDB 的数据是UUID。但在生产中它插入为LUUID,我在生产中也需要它作为UUID,可能是什么原因?

c# mongodb asp.net-core uuid guid
1个回答
0
投票

我也遇到了同样的事情。据我所知,MongoDB 驱动程序的默认

GuidRepresentation
CSharpLegacy
。从 Mongo 源中提取 UUID 在 C# 应用程序中看起来很好,但将数据插入 Mongo 将产生 LUUID(旧版 UUID)。

据我所知,您无法在屏幕截图中“修复”此问题,因为这不是行为的根源。我必须在

BsonDefaults
before 实例化要连接的 MongoClient 中设置以下内容:

BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;

一旦创建连接,

GuidRepresentation
就被设置并且据我所知无法更改。 https://mongodb.github.io/mongo-csharp-driver/2.22/html/T_MongoDB_Bson_GuidRepresentation.htm

© www.soinside.com 2019 - 2024. All rights reserved.