-
Type:
Improvement
-
Resolution: Won't Fix
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.2.4
-
Component/s: Builders, Serialization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Update set operator ignores [BsonIgnoreIfNull] attribute and sets value to null. Example code:
public class Entity
{
public int Id { get; set; }
[BsonIgnoreIfNull]
public string S { get; set; }
}
[Test]
public void Test()
{
var collection = new MongoClient().GetDatabase("Test").GetCollection<Entity>("Test");
collection.UpdateOne(x => x.Id == 1, Builders<Entity>.Update.Set(x => x.S, null), new UpdateOptions { IsUpsert = true });
}
The result JSON in MongoDB is:
{
"_id" : NumberInt(1),
"S" : null
}
Expected:
{
"_id" : NumberInt(1)
}