Table of Contents

Class MongoGridFS

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

Represents a GridFS file system.

public class MongoGridFS
Inheritance
MongoGridFS
Inherited Members
Extension Methods

Constructors

MongoGridFS(MongoDatabase)

Initializes a new instance of the MongoGridFS class.

[Obsolete("Use a different constructor instead.")]
public MongoGridFS(MongoDatabase database)

Parameters

database MongoDatabase

The database containing the GridFS collections.

MongoGridFS(MongoDatabase, MongoGridFSSettings)

Initializes a new instance of the MongoGridFS class.

[Obsolete("Use a different constructor instead.")]
public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)

Parameters

database MongoDatabase

The database containing the GridFS collections.

settings MongoGridFSSettings

The GridFS settings.

MongoGridFS(MongoServer, string, MongoGridFSSettings)

Initializes a new instance of the MongoGridFS class.

public MongoGridFS(MongoServer server, string databaseName, MongoGridFSSettings settings)

Parameters

server MongoServer

The server.

databaseName string

The name of the database.

settings MongoGridFSSettings

The settings.

Properties

Chunks

Gets the chunks collection.

public MongoCollection<BsonDocument> Chunks { get; }

Property Value

MongoCollection<BsonDocument>

Database

Gets the database containing the GridFS collections.

public MongoDatabase Database { get; }

Property Value

MongoDatabase

DatabaseName

Gets the database containing the GridFS collections.

public string DatabaseName { get; }

Property Value

string

Files

Gets the files collection.

public MongoCollection<BsonDocument> Files { get; }

Property Value

MongoCollection<BsonDocument>

Server

Gets the server containing the GridFS collections.

public MongoServer Server { get; }

Property Value

MongoServer

Settings

Gets the GridFS settings.

public MongoGridFSSettings Settings { get; }

Property Value

MongoGridFSSettings

Methods

AppendText(string)

Appends UTF-8 encoded text to an existing GridFS file.

public StreamWriter AppendText(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

StreamWriter

A StreamWriter.

CopyTo(string, string)

Copies a GridFS file.

public MongoGridFSFileInfo CopyTo(string sourceFileName, string destFileName)

Parameters

sourceFileName string

The source file name.

destFileName string

The destination file name.

Returns

MongoGridFSFileInfo

The file info of the new GridFS file.

CopyTo(string, string, MongoGridFSCreateOptions)

Copies a GridFS file.

public MongoGridFSFileInfo CopyTo(string sourceFileName, string destFileName, MongoGridFSCreateOptions createOptions)

Parameters

sourceFileName string

The source file name.

destFileName string

The destination file name.

createOptions MongoGridFSCreateOptions

The create options.

Returns

MongoGridFSFileInfo

The file info of the new GridFS file.

Create(string)

Creates or overwrites a GridFS file.

public MongoGridFSStream Create(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

MongoGridFSStream

A stream.

Create(string, MongoGridFSCreateOptions)

Creates or overwrites a GridFS file.

public MongoGridFSStream Create(string remoteFileName, MongoGridFSCreateOptions createOptions)

Parameters

remoteFileName string

The remote file name.

createOptions MongoGridFSCreateOptions

The create options.

Returns

MongoGridFSStream

A stream.

CreateText(string)

Creates or opens a GridFS file for writing UTF-8 encoded text.

public StreamWriter CreateText(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

StreamWriter

A stream writer.

CreateText(string, MongoGridFSCreateOptions)

Creates or opens a GridFS file for writing UTF-8 encoded text.

public StreamWriter CreateText(string remoteFileName, MongoGridFSCreateOptions createOptions)

Parameters

remoteFileName string

The remote file name.

createOptions MongoGridFSCreateOptions

The create options.

Returns

StreamWriter

A stream writer.

Delete(IMongoQuery)

Deletes GridFS files.

public void Delete(IMongoQuery query)

Parameters

query IMongoQuery

A query that specifies the GridFS files to delete.

Delete(string)

Deletes all versions of a GridFS file.

public void Delete(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

DeleteById(BsonValue)

Deletes a GridFS file.

public void DeleteById(BsonValue id)

Parameters

id BsonValue

The GridFS file Id.

Download(Stream, MongoGridFSFileInfo)

Downloads a GridFS file.

public void Download(Stream stream, MongoGridFSFileInfo fileInfo)

Parameters

stream Stream

The destination stream.

fileInfo MongoGridFSFileInfo

The GridFS file.

Download(Stream, IMongoQuery)

Downloads the most recent version of a GridFS file.

public void Download(Stream stream, IMongoQuery query)

Parameters

stream Stream

The destination stream.

query IMongoQuery

The GridFS file.

Download(Stream, IMongoQuery, int)

Downloads a specific version of a GridFS file.

public void Download(Stream stream, IMongoQuery query, int version)

Parameters

stream Stream

The destination stream.

query IMongoQuery

The GridFS file.

version int

The version to download.

Download(Stream, string)

Downloads the most recent version of a GridFS file.

public void Download(Stream stream, string remoteFileName)

Parameters

stream Stream

The destination stream.

remoteFileName string

The remote file name.

Download(Stream, string, int)

Downloads a specific version of a GridFS file.

public void Download(Stream stream, string remoteFileName, int version)

Parameters

stream Stream

The destination stream.

remoteFileName string

The remote file name.

version int

The version to download.

Download(string)

Downloads the most recent version of a GridFS file.

public void Download(string fileName)

Parameters

fileName string

The file name (same local and remote names).

Download(string, MongoGridFSFileInfo)

Downloads a GridFS file.

public void Download(string localFileName, MongoGridFSFileInfo fileInfo)

Parameters

localFileName string

The local file name.

fileInfo MongoGridFSFileInfo

The GridFS file.

Download(string, IMongoQuery)

Downloads the most recent version of a GridFS file.

public void Download(string localFileName, IMongoQuery query)

Parameters

localFileName string

The local file name.

query IMongoQuery

The GridFS file.

Download(string, IMongoQuery, int)

Downloads a specific version of a GridFS file.

public void Download(string localFileName, IMongoQuery query, int version)

Parameters

localFileName string

The local file name.

query IMongoQuery

The GridFS file.

version int

The version to download.

Download(string, int)

Downloads a specific version of a GridFS file.

public void Download(string fileName, int version)

Parameters

fileName string

The file name (same local and remote names).

version int

The version to download.

Download(string, string)

Downloads the most recent version of a GridFS file.

public void Download(string localFileName, string remoteFileName)

Parameters

localFileName string

The local file name.

remoteFileName string

The remote file name.

Download(string, string, int)

Downloads a specific version of a GridFS file.

public void Download(string localFileName, string remoteFileName, int version)

Parameters

localFileName string

The local file name.

remoteFileName string

The remote file name.

version int

The version to download.

EnsureIndexes()

Ensures that the proper indexes for GridFS exist (only creates the new indexes if there are fewer than 1000 GridFS files).

public void EnsureIndexes()

EnsureIndexes(int)

Ensures that the proper indexes for GridFS exist.

public void EnsureIndexes(int maxFiles)

Parameters

maxFiles int

Only create new indexes if there are fewer than this number of GridFS files).

Exists(IMongoQuery)

Tests whether a GridFS file exists.

public bool Exists(IMongoQuery query)

Parameters

query IMongoQuery

The GridFS file.

Returns

bool

True if the GridFS file exists.

Exists(string)

Tests whether a GridFS file exists.

public bool Exists(string remoteFileName)

Parameters

remoteFileName string

The GridFS file.

Returns

bool

True if the GridFS file exists.

ExistsById(BsonValue)

Tests whether a GridFS file exists.

public bool ExistsById(BsonValue id)

Parameters

id BsonValue

The GridFS file.

Returns

bool

True if the GridFS file exists.

Find(IMongoQuery)

Finds matching GridFS files.

public MongoCursor<MongoGridFSFileInfo> Find(IMongoQuery query)

Parameters

query IMongoQuery

A query.

Returns

MongoCursor<MongoGridFSFileInfo>

The matching GridFS files.

Find(string)

Finds matching GridFS files.

public MongoCursor<MongoGridFSFileInfo> Find(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

MongoCursor<MongoGridFSFileInfo>

The matching GridFS files.

FindAll()

Finds all GridFS files.

public MongoCursor<MongoGridFSFileInfo> FindAll()

Returns

MongoCursor<MongoGridFSFileInfo>

The matching GridFS files.

FindOne(IMongoQuery)

Finds the most recent version of a GridFS file.

public MongoGridFSFileInfo FindOne(IMongoQuery query)

Parameters

query IMongoQuery

The GridFS file.

Returns

MongoGridFSFileInfo

The matching GridFS file.

FindOne(IMongoQuery, int)

Finds a specific version of a GridFS file.

public MongoGridFSFileInfo FindOne(IMongoQuery query, int version)

Parameters

query IMongoQuery

The GridFS file.

version int

The version to find (1 is oldest, -1 is newest, 0 is no sort).

Returns

MongoGridFSFileInfo

The matching GridFS file.

FindOne(string)

Finds the most recent version of a GridFS file.

public MongoGridFSFileInfo FindOne(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

MongoGridFSFileInfo

The matching GridFS file.

FindOne(string, int)

Finds a specific version of a GridFS file.

public MongoGridFSFileInfo FindOne(string remoteFileName, int version)

Parameters

remoteFileName string

The remote file name.

version int

The version to find.

Returns

MongoGridFSFileInfo

The matching GridFS file.

FindOneById(BsonValue)

Finds a GridFS file.

public MongoGridFSFileInfo FindOneById(BsonValue id)

Parameters

id BsonValue

The GridFS file Id.

Returns

MongoGridFSFileInfo

The GridFS file.

MoveTo(string, string)

Moves the most recent version of a GridFS file.

public void MoveTo(string sourceFileName, string destFileName)

Parameters

sourceFileName string

The source file name.

destFileName string

The destination file name.

Open(string, FileMode)

Opens a GridFS file with the specified mode.

public MongoGridFSStream Open(string remoteFileName, FileMode mode)

Parameters

remoteFileName string

The remote file name.

mode FileMode

The mode.

Returns

MongoGridFSStream

A stream.

Open(string, FileMode, FileAccess)

Opens a GridFS file with the specified mode and access.

public MongoGridFSStream Open(string remoteFileName, FileMode mode, FileAccess access)

Parameters

remoteFileName string

The remote file name.

mode FileMode

The mode.

access FileAccess

The access.

Returns

MongoGridFSStream

A stream.

Open(string, FileMode, FileAccess, MongoGridFSCreateOptions)

Opens a GridFS file with the specified mode, access and create options.

public MongoGridFSStream Open(string remoteFileName, FileMode mode, FileAccess access, MongoGridFSCreateOptions createOptions)

Parameters

remoteFileName string

The remote file name.

mode FileMode

The mode.

access FileAccess

The access.

createOptions MongoGridFSCreateOptions

The create options.

Returns

MongoGridFSStream

A stream.

OpenRead(string)

Opens an existing GridFS file for reading.

public MongoGridFSStream OpenRead(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

MongoGridFSStream

A stream.

OpenText(string)

Opens an existing UTF-8 encoded text GridFS file for reading.

public StreamReader OpenText(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

StreamReader

A stream reader.

OpenWrite(string)

Opens an existing GridFS file for writing.

public MongoGridFSStream OpenWrite(string remoteFileName)

Parameters

remoteFileName string

The remote file name.

Returns

MongoGridFSStream

A stream.

OpenWrite(string, MongoGridFSCreateOptions)

Opens an existing GridFS file for writing.

public MongoGridFSStream OpenWrite(string remoteFileName, MongoGridFSCreateOptions createOptions)

Parameters

remoteFileName string

The remote file name.

createOptions MongoGridFSCreateOptions

The create options.

Returns

MongoGridFSStream

A stream.

SetAliases(MongoGridFSFileInfo, string[])

Sets the aliases for an existing GridFS file.

public void SetAliases(MongoGridFSFileInfo fileInfo, string[] aliases)

Parameters

fileInfo MongoGridFSFileInfo

The GridFS file.

aliases string[]

The aliases.

SetContentType(MongoGridFSFileInfo, string)

Sets the content type for an existing GridFS file.

public void SetContentType(MongoGridFSFileInfo fileInfo, string contentType)

Parameters

fileInfo MongoGridFSFileInfo

The GridFS file.

contentType string

The content type.

SetMetadata(MongoGridFSFileInfo, BsonValue)

Sets the metadata for an existing GridFS file.

public void SetMetadata(MongoGridFSFileInfo fileInfo, BsonValue metadata)

Parameters

fileInfo MongoGridFSFileInfo

The GridFS file.

metadata BsonValue

The metadata.

Upload(Stream, string)

Uploads a GridFS file.

public MongoGridFSFileInfo Upload(Stream stream, string remoteFileName)

Parameters

stream Stream

The source stream.

remoteFileName string

The remote file name.

Returns

MongoGridFSFileInfo

The file info of the new GridFS file.

Upload(Stream, string, MongoGridFSCreateOptions)

Uploads a GridFS file.

public MongoGridFSFileInfo Upload(Stream stream, string remoteFileName, MongoGridFSCreateOptions createOptions)

Parameters

stream Stream

The source stream.

remoteFileName string

The remote file name.

createOptions MongoGridFSCreateOptions

The create options.

Returns

MongoGridFSFileInfo

The file info of the new GridFS file.

Upload(string)

Uploads a GridFS file.

public MongoGridFSFileInfo Upload(string fileName)

Parameters

fileName string

The file name (same local and remote names).

Returns

MongoGridFSFileInfo

The file info of the new GridFS file.

Upload(string, string)

Uploads a GridFS file.

public MongoGridFSFileInfo Upload(string localFileName, string remoteFileName)

Parameters

localFileName string

The local file name.

remoteFileName string

The remote file name.

Returns

MongoGridFSFileInfo

The file info of the new GridFS file.