Skip to content

Commit 3c7c673

Browse files
author
Hugo Bonacci
committed
Changed the way that stored documents were updated
1 parent 956647d commit 3c7c673

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

MongoCollection.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,20 @@ private void _PerformUpdates() {
184184

185185
//if this hasn't changed then skip it
186186
if (item.Key.Equals(item.Value.GetObjectHash())) { continue; }
187-
Console.WriteLine("Updating " + item.Value.Get<string>("name"));
188187

189-
this.Find().FindById(item.Value.Id).Set(item.Value);
190-
this.Find().FindById(item.Value.Id).Unset(item.Value.GetRemovedFields().ToArray());
188+
//create a bson document of the update to create
189+
BsonDocument update = new BsonDocument();
190+
update.Merge(item.Value);
191+
update.Remove(Mongo.DocumentIdKey);
192+
193+
//start with the update
194+
this.Find().FindById(item.Value.Id).Set(update);
195+
196+
//check for anything removed
197+
IEnumerable<string> removed = item.Value.GetRemovedFields();
198+
if (removed.Count() > 0) {
199+
this.Find().FindById(item.Value.Id).Unset(removed.ToArray());
200+
}
191201

192202
//Might want to try and merge this into the same
193203
//request to avoid two trips to the database -- But

0 commit comments

Comments
 (0)