Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CH.Bson.Test/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void DiffAFieldAddedAndAFieldModified()

var expectedDiff = new BsonDocument
{
{"+a:newField", 3},
{"+a:newField", newFieldValue},
{
existingField, new BsonDocument
{
Expand Down
17 changes: 7 additions & 10 deletions CH.Bson/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public static BsonDocument Diff(this BsonDocument a, BsonDocument b)
{
var bson = ProcessDifferencesInDocument(a, b);


bson.Add(ProcessFields(a, b));

return bson;
Expand All @@ -73,16 +72,14 @@ private static BsonDocument ProcessDifferencesInDocument(this BsonDocument a, Bs
{
var bson = new BsonDocument();

if (!a.HasSameElementNamesAs(b))
foreach (var e in a.Where(e => !b.Contains(e.Name)))
{
bson.SetElement(new BsonElement("+a:" + e.Name, e.Value));
}

foreach (var e in b.Where(e => !a.Contains(e.Name)))
{
foreach (var e in a.Where(e => !b.Contains(e.Name)))
{
bson.SetElement(new BsonElement("+a:" + e.Name, e.Value));
}
foreach (var e in b.Where(e => !a.Contains(e.Name)))
{
bson.SetElement(new BsonElement("+b:" + e.Name, e.Value));
}
bson.SetElement(new BsonElement("+b:" + e.Name, e.Value));
}

return bson;
Expand Down