Details
-
Improvement
-
Resolution: Won't Fix
-
Major - P3
-
None
-
2.2.4
-
None
Description
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)
|
}
|