Skip to content

Commit d1d7e42

Browse files
committed
CSHARP-1191: Added DropAsync method to GridFSBucket.
1 parent edbab3c commit d1d7e42

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/MongoDB.Driver.GridFS/GridFSBucket.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ public ImmutableGridFSBucketOptions Options
155155
}
156156
}
157157

158+
/// <inheritdoc />
159+
public async Task DropAsync(CancellationToken cancellationToken = default(CancellationToken))
160+
{
161+
var filesCollectionNamespace = GetFilesCollectionNamespace();
162+
var chunksCollectionNamespace = GetChunksCollectionNamespace();
163+
var messageEncoderSettings = GetMessageEncoderSettings();
164+
165+
using (var binding = await GetSingleServerReadWriteBindingAsync(cancellationToken).ConfigureAwait(false))
166+
{
167+
var filesCollectionDropOperation = new DropCollectionOperation(filesCollectionNamespace, messageEncoderSettings);
168+
await filesCollectionDropOperation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false);
169+
170+
var chunksCollectionDropOperation = new DropCollectionOperation(chunksCollectionNamespace, messageEncoderSettings);
171+
await chunksCollectionDropOperation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false);
172+
}
173+
}
174+
158175
/// <inheritdoc />
159176
public async Task<IAsyncCursor<GridFSFileInfo>> FindAsync(FilterDefinition<GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
160177
{

src/MongoDB.Driver.GridFS/IGridFSBucket.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public interface IGridFSBucket
9090
/// <returns>A Task.</returns>
9191
Task DownloadToStreamByNameAsync(string filename, Stream destination, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
9292

93+
/// <summary>
94+
/// Drops the files and chunks collections associated with this GridFS bucket.
95+
/// </summary>
96+
/// <param name="cancellationToken">The cancellation token.</param>
97+
/// <returns>A Task.</returns>
98+
Task DropAsync(CancellationToken cancellationToken = default(CancellationToken));
99+
93100
/// <summary>
94101
/// Finds matching entries from the files collection.
95102
/// </summary>

0 commit comments

Comments
 (0)