Table of Contents

Class GridFSBucket<TFileId>

Namespace
MongoDB.Driver.GridFS
Assembly
MongoDB.Driver.GridFS.dll

Represents a GridFS bucket.

public class GridFSBucket<TFileId> : IGridFSBucket<TFileId>

Type Parameters

TFileId

The type of the file identifier.

Inheritance
GridFSBucket<TFileId>
Implements
IGridFSBucket<TFileId>
Derived
Inherited Members

Constructors

GridFSBucket(IMongoDatabase, GridFSBucketOptions)

Initializes a new instance of the GridFSBucket class.

public GridFSBucket(IMongoDatabase database, GridFSBucketOptions options = null)

Parameters

database IMongoDatabase

The database.

options GridFSBucketOptions

The options.

Properties

Database

Gets the database where the GridFS files are stored.

public IMongoDatabase Database { get; }

Property Value

IMongoDatabase

The database.

Options

Gets the options.

public ImmutableGridFSBucketOptions Options { get; }

Property Value

ImmutableGridFSBucketOptions

The options.

Methods

Delete(TFileId, CancellationToken)

Deletes a file from GridFS.

public void Delete(TFileId id, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

cancellationToken CancellationToken

The cancellation token.

DeleteAsync(TFileId, CancellationToken)

Deletes a file from GridFS.

public Task DeleteAsync(TFileId id, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

DownloadAsBytes(TFileId, GridFSDownloadOptions, CancellationToken)

Downloads a file stored in GridFS and returns it as a byte array.

public byte[] DownloadAsBytes(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

byte[]

The contents of the file stored in GridFS.

DownloadAsBytesAsync(TFileId, GridFSDownloadOptions, CancellationToken)

Downloads a file stored in GridFS and returns it as a byte array.

public Task<byte[]> DownloadAsBytesAsync(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<byte[]>

A Task whose result is a byte array containing the contents of the file stored in GridFS.

DownloadAsBytesByName(string, GridFSDownloadByNameOptions, CancellationToken)

Downloads a file stored in GridFS and returns it as a byte array.

public byte[] DownloadAsBytesByName(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

options GridFSDownloadByNameOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

byte[]

A byte array containing the contents of the file stored in GridFS.

DownloadAsBytesByNameAsync(string, GridFSDownloadByNameOptions, CancellationToken)

Downloads a file stored in GridFS and returns it as a byte array.

public Task<byte[]> DownloadAsBytesByNameAsync(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

options GridFSDownloadByNameOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<byte[]>

A Task whose result is a byte array containing the contents of the file stored in GridFS.

DownloadToStream(TFileId, Stream, GridFSDownloadOptions, CancellationToken)

Downloads a file stored in GridFS and writes the contents to a stream.

public void DownloadToStream(TFileId id, Stream destination, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

destination Stream

The destination.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

DownloadToStreamAsync(TFileId, Stream, GridFSDownloadOptions, CancellationToken)

Downloads a file stored in GridFS and writes the contents to a stream.

public Task DownloadToStreamAsync(TFileId id, Stream destination, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

destination Stream

The destination.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

DownloadToStreamByName(string, Stream, GridFSDownloadByNameOptions, CancellationToken)

Downloads a file stored in GridFS and writes the contents to a stream.

public void DownloadToStreamByName(string filename, Stream destination, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

destination Stream

The destination.

options GridFSDownloadByNameOptions

The options.

cancellationToken CancellationToken

The cancellation token.

DownloadToStreamByNameAsync(string, Stream, GridFSDownloadByNameOptions, CancellationToken)

Downloads a file stored in GridFS and writes the contents to a stream.

public Task DownloadToStreamByNameAsync(string filename, Stream destination, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

destination Stream

The destination.

options GridFSDownloadByNameOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

Drop(CancellationToken)

Drops the files and chunks collections associated with this GridFS bucket.

public void Drop(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

DropAsync(CancellationToken)

Drops the files and chunks collections associated with this GridFS bucket.

public Task DropAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

Find(FilterDefinition<GridFSFileInfo<TFileId>>, GridFSFindOptions<TFileId>, CancellationToken)

Finds matching entries from the files collection.

public IAsyncCursor<GridFSFileInfo<TFileId>> Find(FilterDefinition<GridFSFileInfo<TFileId>> filter, GridFSFindOptions<TFileId> options = null, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<GridFSFileInfo<TFileId>>

The filter.

options GridFSFindOptions<TFileId>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<GridFSFileInfo<TFileId>>

A cursor of files collection documents.

FindAsync(FilterDefinition<GridFSFileInfo<TFileId>>, GridFSFindOptions<TFileId>, CancellationToken)

Finds matching entries from the files collection.

public Task<IAsyncCursor<GridFSFileInfo<TFileId>>> FindAsync(FilterDefinition<GridFSFileInfo<TFileId>> filter, GridFSFindOptions<TFileId> options = null, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<GridFSFileInfo<TFileId>>

The filter.

options GridFSFindOptions<TFileId>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<GridFSFileInfo<TFileId>>>

A Task whose result is a cursor of files collection documents.

OpenDownloadStream(TFileId, GridFSDownloadOptions, CancellationToken)

Opens a Stream that can be used by the application to read data from a GridFS file.

public GridFSDownloadStream<TFileId> OpenDownloadStream(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

GridFSDownloadStream<TFileId>

A Stream.

OpenDownloadStreamAsync(TFileId, GridFSDownloadOptions, CancellationToken)

Opens a Stream that can be used by the application to read data from a GridFS file.

public Task<GridFSDownloadStream<TFileId>> OpenDownloadStreamAsync(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<GridFSDownloadStream<TFileId>>

A Task whose result is a Stream.

OpenDownloadStreamByName(string, GridFSDownloadByNameOptions, CancellationToken)

Opens a Stream that can be used by the application to read data from a GridFS file.

public GridFSDownloadStream<TFileId> OpenDownloadStreamByName(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

options GridFSDownloadByNameOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

GridFSDownloadStream<TFileId>

A Stream.

OpenDownloadStreamByNameAsync(string, GridFSDownloadByNameOptions, CancellationToken)

Opens a Stream that can be used by the application to read data from a GridFS file.

public Task<GridFSDownloadStream<TFileId>> OpenDownloadStreamByNameAsync(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

options GridFSDownloadByNameOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<GridFSDownloadStream<TFileId>>

A Task whose result is a Stream.

OpenUploadStream(TFileId, string, GridFSUploadOptions, CancellationToken)

Opens a Stream that can be used by the application to write data to a GridFS file.

public GridFSUploadStream<TFileId> OpenUploadStream(TFileId id, string filename, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

filename string

The filename.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

GridFSUploadStream<TFileId>

A Stream.

OpenUploadStreamAsync(TFileId, string, GridFSUploadOptions, CancellationToken)

Opens a Stream that can be used by the application to write data to a GridFS file.

public Task<GridFSUploadStream<TFileId>> OpenUploadStreamAsync(TFileId id, string filename, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

filename string

The filename.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<GridFSUploadStream<TFileId>>

A Task whose result is a Stream.

Rename(TFileId, string, CancellationToken)

Renames a GridFS file.

public void Rename(TFileId id, string newFilename, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

newFilename string

The new filename.

cancellationToken CancellationToken

The cancellation token.

RenameAsync(TFileId, string, CancellationToken)

Renames a GridFS file.

public Task RenameAsync(TFileId id, string newFilename, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

newFilename string

The new filename.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

UploadFromBytes(TFileId, string, byte[], GridFSUploadOptions, CancellationToken)

Uploads a file (or a new revision of a file) to GridFS.

public void UploadFromBytes(TFileId id, string filename, byte[] source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

filename string

The filename.

source byte[]

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

UploadFromBytesAsync(TFileId, string, byte[], GridFSUploadOptions, CancellationToken)

Uploads a file (or a new revision of a file) to GridFS.

public Task UploadFromBytesAsync(TFileId id, string filename, byte[] source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

filename string

The filename.

source byte[]

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

UploadFromStream(TFileId, string, Stream, GridFSUploadOptions, CancellationToken)

Uploads a file (or a new revision of a file) to GridFS.

public void UploadFromStream(TFileId id, string filename, Stream source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

filename string

The filename.

source Stream

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

UploadFromStreamAsync(TFileId, string, Stream, GridFSUploadOptions, CancellationToken)

Uploads a file (or a new revision of a file) to GridFS.

public Task UploadFromStreamAsync(TFileId id, string filename, Stream source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id TFileId

The file id.

filename string

The filename.

source Stream

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.