我正在运行Mongodb的2.06版本和10Gen提供的C#驱动程序的版本(1.5).
我的每个实体都有一个Id属性设置......
[BsonId(IdGenerator = typeof(GuidGenerator))]
public Guid Id { get; set; }
Run Code Online (Sandbox Code Playgroud)
Id字段存储为Binary - 3:UuidLegacy.因为我在实体上调用ToJson()时它是如何存储的,它会为Id返回以下javascript对象.
_id : Object
$binary: "some values here"
$type: "03"
Run Code Online (Sandbox Code Playgroud)
这显然是因为数据存储为Binary = 3:UuidLegacy.这是有道理的.
我想在我的Javascript代码中使用实际的Guid.如果我将我的Id属性看起来如下,那么它对MongoDB的效率如何?
[BsonId(IdGenerator = typeof(GuidGenerator)),MongoDB.Bson.Serialization.Attributes.BsonRepresentation(BsonType.String)]
public Guid Id { get; set; }
Run Code Online (Sandbox Code Playgroud)
这使得mongodb将我的Id存储为字符串.但这真的有多高效?我猜我的Id的二进制格式更好,但我真的需要Guid.
我如何从二进制 - 3:uuidLegacy转到我在json中需要的Guid?
我想另一个想法是我可以使用发送给我的$ binary值吗?我使用Id执行查找,例如我的查询字符串的一部分.
谢谢,