kalit February 2016

MongoDB - document is adding with luuid

I have problem with add document to collection from C#.

I have model in my program

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

And the problem is in my database. All documents are saveing with LUUID but no with CSUUID and i cannot eg. find by id

Answers


Lamar Oliphant February 2016

Try to use a string type for the C# object, but with a serialization attribute:

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; }
}

Post Status

Asked in February 2016
Viewed 2,415 times
Voted 8
Answered 1 times

Search




Leave an answer