Question Details

No question body available.

Tags

c# .net mongodb upsert

Answers (1)

October 5, 2025 Score: 1 Rep: 680 Quality: Low Completeness: 40%

You can use the [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] attribute on your model properties.

This tells the serializer not to include the property in the JSON if it has the default value.

public class ShipmentDto
{
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
    public bool IsActive { get; set; }  // default is false

}