I'm trying to have a partial update on one of my documents in MongoDB, using C# driver. I've followed the following posts:
How do you update multiple field using Update.Set in MongoDB using official c# driver?
Partial mongodb upsert using the c# driver?
I get the following error when trying to do the update: "Only classes can be mapped currently", in the AutoMapper CreateClassMap class, the type received is System.Collections.Generic.IEnumerable`1[[MongoDB.Bson.BsonElement, MongoDB.Bson]], where it cannot be an interface.
The code I'm using is:
public void UpdateObjectByFields<T>(int id, Dictionary<string, object> modifiedFields)
where T : class
{
var collection = m_MongoDatabase.GetCollection<T>();
var builder = new UpdateBuilder();
foreach (var modifiedField in modifiedFields)
{
builder.Set(modifiedField.Key, modifiedField.Value.ToString());
}
collection.Update(Query.EQ("_id", id), builder);
}
where the T type is a valid collection in the Mongo.
What am I doing wrong?
Thanks, Nir