JSON必须如何将MongoDB迫使Bindata子类型4
我正在使用C#驱动程序mongodb.driver 2.16.0 我正在尝试插入纯JSON。 我希望_id用作新的UUID类型AKA Bindata subtype 4。但是我只能得到Subtype 3或纯字符串。
var testColl = db.GetCollection<BsonDocument>("test");
var testJson = "[{'_id':CSUUID('609e26f6-dbad-4dba-ba37-4e35f0e348ec'),'name':'Data1'},{'_id':CSUUID('609e26f6-dbad-4dba-ba37-4e35f0e348ff'),'name':'Data2'}]";
testColl.InsertMany(BsonSerializer.Deserialize<BsonDocument[]>(testJson));
我尝试了'_id':'609E26F6-DBAD-4DBA-BA37-4E35F0E348EC',导致字符串。
我尝试了'_id':uuid('609e26f6-dbad-4dba-ba37-4e35f0e348ec'),在Subtype 3中进行了混音。
示例代码还会导致
子类型3。
I'm using the c# driver MongoDB.Driver 2.16.0
I'm trying to insert pure json.
I want the _id to be used as the new UUID type aka BinData subtype 4. But I get only subtype 3 or pure string.
var testColl = db.GetCollection<BsonDocument>("test");
var testJson = "[{'_id':CSUUID('609e26f6-dbad-4dba-ba37-4e35f0e348ec'),'name':'Data1'},{'_id':CSUUID('609e26f6-dbad-4dba-ba37-4e35f0e348ff'),'name':'Data2'}]";
testColl.InsertMany(BsonSerializer.Deserialize<BsonDocument[]>(testJson));
I tried '_id':'609e26f6-dbad-4dba-ba37-4e35f0e348ec' which results in a string.
I tried '_id':UUID('609e26f6-dbad-4dba-ba37-4e35f0e348ec') which rusults in subtype 3.
And the example code also results in subtype 3.
How must the json look to make a subtype 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有以下选项:
配置
bsondefaults.guidrepresentationmode = guidrePresentationMode.v3;
。在这种情况下,您将使用文档中指定的子类型(或通过属性在最后查看文档)。如果是csuuid
- ,那么子类型为3,uuid
-4。配置
guidserialization.unspecified
。例如,在收集期间创建:这种情况类似于#1,我们从文档中获得了子类型,但仅适用于特定集合
配置
guid> guidserialization.standard
强迫使用此特定集合的子类型
,无论subtype
在文档中提供:您还可以在全球范围内配置GuidRepresentation:
bsondefaults.guidrepresentation = guidrepresentation.standard;
。在这种情况下,您将默认情况下强制使用此表示形式(对于guidrepresentationmode.v2默认模式),您可以找到详细信息在这里
You have the following options:
Configure
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
. In this case, you will work with subTypes specified in the document (or via attributes see the doc in the end). If it'sCSUUID
- then subType is 3,UUID
- 4.Configure
GuidSerialization.Unspecified
. For example during collection creating:this case is similar to #1 where we get used subType from a document, but only for a particular collection
Configuring
GuidSerialization.Standard
to force using this particularsubType
for a collection regardless asubType
provided in the document:You also can configure GuidRepresentation globally like:
BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;
. In this case you will force using this representation by default everywhere (for GuidRepresentationMode.V2 which is default mode)You can find details here