I don't understand why I am getting a duplicate key exception on Save. I thought the point of save was to update if there, insert if not. Here is the error.
WriteConcern detected an error 'E11000 duplicate key error index: cms.BaseVariables.$id dup key: { : "8f69cb40ab3568957c237ef360d29964" }'. (Response was { "err" : "E11000 duplicate key error index: cms.BaseVariables.$id dup key: { : \"8f69cb40ab3568957c237ef360d29964\" }", "code" : 11000, "n" : 0, "connectionId" : 6969, "ok" : 1.0 }).
Yes it is right, 8f69cb40ab3568957c237ef360d29964 is there already. So why is it not just updating it?
I have the following class map registration and ID property on the object...
BsonClassMap.RegisterClassMap<BaseVariableGroup>(cm =>
{
cm.AutoMap();
cm.SetIdMember(cm.GetMemberMap(c => c.Id));
cm.IdMemberMap.SetIdGenerator(StringObjectIdGenerator.Instance);
});
public string Id
{
get { return _id; }
set
{
_id = value;
_id = Md5Cryptography.Hash(string.Concat(SportId, CompetitionId, Round));
}
}
And this is how I am calling Save...
_collection.Save(baseVariableGroup)
The exception...
