Hi, I have a project worked with mongoDb Driver 2.2.0
And there’s a object defined as:
public class ClassToSave
{
[BsonId] public int Id { get; set; } = 0;
public IInterface[] Data { get; set; } = new IInterface[] { new ArrayItem() };
}
public class ArrayItem : IInterface
{
[BsonId]
public string Name { get; set; } = "Test";
}
public interface IInterface
{
string Name { get; set; }
}
And the exception happened when insert data to db.
BsonClassMap.RegisterClassMap<ArrayItem>(cm =>
{
var fullName = typeof(ArrayItem).FullName;
cm.SetDiscriminator(fullName);
cm.AutoMap();
cm.SetIgnoreExtraElements(true);
});
var client = new MongoClient();
var db = client.GetDatabase("MyTest");
var collection = db.GetCollection<ClassToSave>("collection");
collection.InsertOne(new ClassToSave());
Detail of the Exception:
How can I solve this?