Table of Contents

Class GridFSBucket

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

Represents a GridFS bucket.

public class GridFSBucket : GridFSBucket<ObjectId>, IGridFSBucket, IGridFSBucket<ObjectId>
Inheritance
GridFSBucket
Implements
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.

Methods

Delete(BsonValue, CancellationToken)

Deletes a file from GridFS.

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

Parameters

id BsonValue

The file id.

cancellationToken CancellationToken

The cancellation token.

DeleteAsync(BsonValue, CancellationToken)

Deletes a file from GridFS.

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

Parameters

id BsonValue

The file id.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

DownloadAsBytes(BsonValue, GridFSDownloadOptions, CancellationToken)

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

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

Parameters

id BsonValue

The file id.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

byte[]

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

DownloadAsBytesAsync(BsonValue, GridFSDownloadOptions, CancellationToken)

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

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

Parameters

id BsonValue

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.

DownloadToStream(BsonValue, Stream, GridFSDownloadOptions, CancellationToken)

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

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

Parameters

id BsonValue

The file id.

destination Stream

The destination.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

DownloadToStreamAsync(BsonValue, Stream, GridFSDownloadOptions, CancellationToken)

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

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

Parameters

id BsonValue

The file id.

destination Stream

The destination.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

Find(FilterDefinition<GridFSFileInfo>, GridFSFindOptions, CancellationToken)

Finds matching entries from the files collection.

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

Parameters

filter FilterDefinition<GridFSFileInfo>

The filter.

options GridFSFindOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<GridFSFileInfo>

A cursor of files collection documents.

FindAsync(FilterDefinition<GridFSFileInfo>, GridFSFindOptions, CancellationToken)

Finds matching entries from the files collection.

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

Parameters

filter FilterDefinition<GridFSFileInfo>

The filter.

options GridFSFindOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<GridFSFileInfo>>

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

OpenDownloadStream(BsonValue, GridFSDownloadOptions, CancellationToken)

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

public GridFSDownloadStream OpenDownloadStream(BsonValue id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default)

Parameters

id BsonValue

The file id.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

GridFSDownloadStream

A Stream.

OpenDownloadStreamAsync(BsonValue, GridFSDownloadOptions, CancellationToken)

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

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

Parameters

id BsonValue

The file id.

options GridFSDownloadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<GridFSDownloadStream>

A Task whose result is a Stream.

OpenUploadStream(string, GridFSUploadOptions, CancellationToken)

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

public GridFSUploadStream OpenUploadStream(string filename, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

GridFSUploadStream

A Stream.

OpenUploadStreamAsync(string, GridFSUploadOptions, CancellationToken)

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

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

Parameters

filename string

The filename.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<GridFSUploadStream>

A Task whose result is a Stream.

Rename(BsonValue, string, CancellationToken)

Renames a GridFS file.

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

Parameters

id BsonValue

The file id.

newFilename string

The new filename.

cancellationToken CancellationToken

The cancellation token.

RenameAsync(BsonValue, string, CancellationToken)

Renames a GridFS file.

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

Parameters

id BsonValue

The file id.

newFilename string

The new filename.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task.

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

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

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

Parameters

filename string

The filename.

source byte[]

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ObjectId

The id of the new file.

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

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

public Task<ObjectId> UploadFromBytesAsync(string filename, byte[] source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

source byte[]

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ObjectId>

A Task whose result is the id of the new file.

UploadFromStream(string, Stream, GridFSUploadOptions, CancellationToken)

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

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

Parameters

filename string

The filename.

source Stream

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ObjectId

The id of the new file.

UploadFromStreamAsync(string, Stream, GridFSUploadOptions, CancellationToken)

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

public Task<ObjectId> UploadFromStreamAsync(string filename, Stream source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default)

Parameters

filename string

The filename.

source Stream

The source.

options GridFSUploadOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ObjectId>

A Task whose result is the id of the new file.