You'll need to use update just like you did for the Detail
. If you just use the native serialization of an entire C# class into a MongoDB collection, you'll overwrite the entire document as you've seen.
public class MyEntry
{
public ObjectId Id { get; set; }
public string SimpleHash { get; set; }
public string GroupIdentifier { get; set; }
}
var update = Update<MyEntry>.Combine(
Update<MyEntry>.Set(m => SimpleHash, "TheHash!"),
Update<MyEntry>.Set(m => GroupIdentifier, "MyGroup"));
Then, Update
the document into the collection using a query, passing the update
builder object above. (Of course, you can vary the properties as needed). I like this approach better than trying to merge an object, as it means that I don't need to worry about partially loaded C# objects or accidentally removing properties from the MongoDB document because they weren't set.
I'd expect that you may need to add the attribute [BsonIgnoreExtraElements]
to your MyEntry class during derserialization or the driver may throw an error when it encounters the unexpected extra data.