using MongoDB.Bson.Serialization; [BsonIgnoreExtraElements] public class Customer { [BsonId] public int CustomerId { get; set; } //this is our primary key field public string Name { get; set; } public string Email { get; set; } } //configure the mapping for our customer class BsonClassMap.RegisterClassMapIn this example, we have defined a Customer class with a CustomerId property that we want to use as the primary key field. We then configure the mapping for our Customer class using BsonClassMap.RegisterClassMap(). We specify that the CustomerId property should be used as the primary key field by calling BsonClassMap.MapIdProperty() and passing in a lambda expression that returns the CustomerId property. The MongoDB C#/.NET driver is available as a NuGet package, which you can install using Visual Studio or the NuGet command-line tool.(cm => { cm.AutoMap(); cm.MapIdProperty(c => c.CustomerId); //specify that CustomerId should be used as the primary key });