/// <summary> /// Partials the delete entity. /// </summary> /// <typeparam name="TObject">The type of the object.</typeparam> /// <param name="dbCollectionName">Name of the database collection.</param> /// <param name="parser">The parser.</param> /// <param name="uri">The URI.</param> /// <exception cref="WitsmlException"></exception> protected void PartialDeleteEntity <TObject>(string dbCollectionName, WitsmlQueryParser parser, EtpUri uri) { try { Logger.DebugFormat("Partial Deleting {0} MongoDb collection", dbCollectionName); var collection = GetCollection <TObject>(dbCollectionName); var current = GetEntity <TObject>(uri, dbCollectionName); var updates = MongoDbUtility.CreateUpdateFields <TObject>(); var ignores = MongoDbUtility.CreateIgnoreFields <TObject>(GetIgnoredElementNamesForUpdate(parser)); var partialDelete = new MongoDbDelete <TObject>(Container, collection, parser, IdPropertyName, ignores); partialDelete.PartialDelete(current, uri, updates); var transaction = Transaction; if (transaction == null) { return; } transaction.Attach(MongoDbAction.Update, dbCollectionName, IdPropertyName, current.ToBsonDocument(), uri); transaction.Save(); } catch (MongoException ex) { Logger.ErrorFormat("Error partial deleting {0} MongoDb collection: {1}", dbCollectionName, ex); throw new WitsmlException(ErrorCodes.ErrorUpdatingInDataStore, ex); } }
public void MongoDbUtility_CreateIgnoreFields_Returns_List_Of_common_Objects_To_Ignore() { var commonPropertiesToIgnore = MongoDbUtility.CreateIgnoreFields <Well>(null); Assert.IsTrue(commonPropertiesToIgnore.Count > 0); commonPropertiesToIgnore = MongoDbUtility.CreateIgnoreFields <Witsml200.Well>(null); Assert.IsTrue(commonPropertiesToIgnore.Count > 0); var ignoredList = new List <string> { "dTimLicense" }; commonPropertiesToIgnore = MongoDbUtility.CreateIgnoreFields <Well>(ignoredList); Assert.IsTrue(commonPropertiesToIgnore.Count > 1); Assert.IsTrue(commonPropertiesToIgnore.Contains("dTimLicense")); }