MongoDB - 文档正在添加luuid

时间:2016-02-08 07:59:29

标签: c# mongodb

我有从C#向集合中添加文档的问题。

我的程序中有模型

public class Object
{
    public Guid Id { get; set; }
    public long StartTimestamp { get; set; }
    public long EndTimestamp { get; set; }
}

问题出在我的数据库中。所有文件都使用LUUID保存,但没有使用CSUUID保存,我也不能保存。按ID

查找

1 个答案:

答案 0 :(得分:0)

尝试为C#对象使用字符串类型,但使用序列化属性:

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;    

public class Object
{
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; }

    public long StartTimestamp { get; set; }

    public long EndTimestamp { get; set; }
}