此 C# 应用程序需要与 MongoDB 一起使用。当我尝试添加数据时,出现错误:E11000 重复键错误集合:aap.Olas 索引:id重复键:{ : BinData(3, 00000000000000000000000000000000) }
这是将数据添加到数据库的代码
public void Add(IDataType item,string name)
{
IMongoCollection<IDataType> collection = db.GetCollection<IDataType>(name);
collection.InsertOne(item);
}
这就是界面的样子。
using MongoDB.Bson.Serialization.Attributes;
using System;
namespace Labo04.GLOBAL
{
public interface IDataType
{
[BsonId]
Guid Id { get; set; }
}
}
这是 Ola 类,我尝试插入的数据。
public class OLA : IDataType
{
[BsonId]
public Guid Id { get; set; }
public string Code { get; set; }
public string Naam { get; set; }
public int Studiepunten { get; set; }
public virtual List<Docent> Docenten { get; set; }
public virtual OPO Opo { get; set; }
public OLA()
{
}
public OLA(string code, string naam, int studiepunten, List<Docent> docenten, OPO opo)
{
this.Code = code;
this.Naam = naam;
this.Studiepunten = studiepunten;
this.Docenten = docenten;
this.Opo = opo;
}
}
我怎样才能解决这个问题。