Convert .NET Guid to MongoDB ObjectID
问题 How can I convert a .NET GUID to a MongoDB ObjectID (in C#). Also, can I convert it back again to the same GUID from the ObjectID? 回答1: You can't convert ObjectId into GUID and vice versa, because they are two different things(different sizes, algoritms). You can use any type for mongoDb _id including GUID . For example in official c# driver you should specify attribute [BsonId] : [BsonId] public Guid Id {get;set;} [BsonId] public int Id {get;set;} ObjectId: A BSON ObjectID is a 12-byte value