/// <summary> /// Drop an index from a collection /// </summary> public bool DropIndex(string collection, string name) { if (collection.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(collection)); } if (name.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(name)); } if (name == "_id") { throw LiteException.IndexDropId(); } return(this.AutoTransaction(transaction => { var snapshot = transaction.CreateSnapshot(LockMode.Write, collection, false); var col = snapshot.CollectionPage; var indexer = new IndexService(snapshot); // no collection, no index if (col == null) { return false; } // search for index reference var index = col.GetCollectionIndex(name); // no index, no drop if (index == null) { return false; } // delete all data pages + indexes pages indexer.DropIndex(index); // remove index entry in collection page snapshot.CollectionPage.DeleteCollectionIndex(name); return true; })); }