MongoUtility.Command.ElementHelper.ModifyElement C# (CSharp) Method

ModifyElement() public static method

Modify Element
public static ModifyElement ( string elementPath, BsonValue newValue, BsonElement el, BsonDocument currentDocument, MongoCollection currentCollection ) : void
elementPath string
newValue BsonValue
el BsonElement
currentDocument BsonDocument
currentCollection MongoCollection
return void
        public static void ModifyElement(string elementPath, BsonValue newValue, BsonElement el,
            BsonDocument currentDocument, MongoCollection currentCollection)
        {
            var baseDoc = currentDocument;
            var t = GetLastParentDocument(baseDoc, elementPath, false);
            if (t.IsBsonDocument)
            {
                t.AsBsonDocument.SetElement(new BsonElement(el.Name, newValue));
            }
            if (!currentCollection.IsCapped())
            {
                currentCollection.Save(baseDoc);
            }
        }