public static Task <CommandResult> DropAllIndexesAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource <CommandResult>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.DropAllIndexes(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return(tcs.Task); }
/// <summary> /// Drops all indexes on this repository. /// </summary> public virtual void DropAllIndexes() => collection.DropAllIndexes();
/// <summary> /// Drops all indexes on this collection. /// </summary> /// <returns>A <see cref="CommandResult"/>.</returns> public virtual CommandResult DropAllIndexes() { return(_collection.DropAllIndexes()); }
public void TestCreateIndex() { collection.DropAllIndexes(); var indexes = collection.GetIndexes().ToArray(); Assert.AreEqual(1, indexes.Length); Assert.AreEqual("_id_", indexes[0]["name"].AsString); collection.DropAllIndexes(); collection.CreateIndex("x"); indexes = collection.GetIndexes().ToArray(); Assert.AreEqual(2, indexes.Length); Assert.AreEqual("_id_", indexes[0]["name"].AsString); Assert.AreEqual("x_1", indexes[1]["name"].AsString); collection.DropAllIndexes(); collection.CreateIndex(IndexKeys.Ascending("x").Descending("y"), IndexOptions.SetUnique(true)); indexes = collection.GetIndexes().ToArray(); Assert.AreEqual(2, indexes.Length); Assert.AreEqual("_id_", indexes[0]["name"].AsString); Assert.AreEqual("x_1_y_-1", indexes[1]["name"].AsString); Assert.AreEqual(true, indexes[1]["unique"].ToBoolean()); }