I present a simple model:
public class UserDocument
{
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string DisplayName { get; set; }
public List<string> Friends { get; set; }
}
I use the latest C # driver, which has the ability to replace a document with a C # object, which will automatically update all its fields. The problem is that I want to update all fields except the user's friends, because this is a field that contains the relationship of the object with other documents. Of course, I can manually update each field of those that I want to update, and these are just two.
But this example is simple, just to understand. In fact, the fields are much larger, and it would be more difficult to update each field. For each of them, one line is required to use the operator Set. In addition, newly added fields should be supported in the same way, unlike an update that automatically just works.
Is there a way to achieve this - automatically update all fields just by specifying a list of excluded fields?
source
share