Platforms to show: All Mac Windows Linux Cross-Platform

Back to MongoGridFSMBS class.

MongoGridFSMBS.Chunks as MongoCollectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns a collection that contains the chunks for files.
Example
Var GridFS As MongoGridFSMBS = Client.GridFS("test", "fs")
Var chunks As MongoCollectionMBS = GridFS.Chunks

// now request content and inspect it
Var item As MongoCursorMBS = chunks.Find("{}")
Var items As String = item.Records
Break

This instance is owned by the GridFS instance and should not be modified or freed.

MongoGridFSMBS.Constructor   Private

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The private constructor.

MongoGridFSMBS.CreateFile(options as MongoGridFSFileOptionsMBS) as MongoGridFSFileMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new file.
Example
Var GridFS As MongoGridFSMBS = Client.GridFS("test", "fs")

Var options As New MongoGridFSFileOptionsMBS
options.FileName = "test.txt"
options.ContentType = "text/plain"

Var file As MongoGridFSFileMBS = GridFS.CreateFile(options)
Var BytesWritten As Integer = file.Write("Hello World")
file.Save

MongoGridFSMBS.CreateFileFromStream(stream as MongoStreamMBS, options as MongoGridFSFileOptionsMBS) as MongoGridFSFileMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new file and fill it with the contents of the stream.
Example
// create a file from a file on disk
Var options As New MongoGridFSFileOptionsMBS
options.FileName = "test.pdf"
options.ContentType = "application/pdf"

Var stream As MongoStreamMBS = MongoStreamMBS.NewStreamFromPath("/Users/cs/Desktop/Installation.pdf")
Var file As MongoGridFSFileMBS = GridFS.CreateFileFromStream(stream, options)

Note that this function will read from stream until End of File, making it best suited for file-backed streams.

Some examples using this method:

MongoGridFSMBS.Drop

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Requests that an entire GridFS be dropped, including all files associated with it.

MongoGridFSMBS.Files as MongoCollectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Retrieves the collection containing the file metadata for GridFS.
Example
Var GridFS As MongoGridFSMBS = Client.GridFS("test", "fs")
Var Files As MongoCollectionMBS = GridFS.Files

// now request content and inspect it
Var item As MongoCursorMBS = Files.Find("{}")
Var items As String = item.Records
Break

MongoGridFSMBS.Find(filterJSON as String, OptionsJSON as String = "") as MongoGridFSFileListMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds all gridfs files matching filter.

You can iterate the matched gridfs files with the resulting file list.

See Find() in MongoCollectionMBS for a description of the filter and opts parameters.

This function is considered a retryable read operation. Upon a transient error (a network error, errors due to replica set failover, etc.) the operation is safely retried once. If retryreads is false in the URI, the retry behavior does not apply.

MongoGridFSMBS.Find2(filterJSON as String, OptionsJSON as String = "") as MongoGridFSFileMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds all gridfs files matching filter.
Example
// find all files
Var GridFS As MongoGridFSMBS = Client.GridFS("test", "fs")
Var files() As MongoGridFSFileMBS = GridFS.Find2("{}")

Same as Find() but returns a Xojo array with all files.

MongoGridFSMBS.FindOne(filterJSON as String, OptionsJSON as String = "") as MongoGridFSFileMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Find the first GridFS file matching filter.

If there is an error, nil is returned and an exception is reported; if there is no error but no matching file is found, nil is returned.

See Find() for a description of the filter and opts parameters.

This function is considered a retryable read operation. Upon a transient error (a network error, errors due to replica set failover, etc.) the operation is safely retried once. If retryreads is false in the URI, the retry behavior does not apply.

MongoGridFSMBS.FindOneByFileName(FileName as String) as MongoGridFSFileMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds the first file matching the filename specified.
Example
Var GridFS As MongoGridFSMBS = Client.GridFS("test", "fs")

// now find the file and read it
Var file As MongoGridFSFileMBS = GridFS.FindOneByFileName( "test.txt")
Var data As String = file.ReadAll

If there is an error, nil is returned and an exception is raised; if there is no error but no matching file is found, nil is returned.

This function is considered a retryable read operation. Upon a transient error (a network error, errors due to replica set failover, etc.) the operation is safely retried once. If retryreads is false in the URI the retry behavior does not apply.

Some examples using this method:

MongoGridFSMBS.RemoveByFileName(Name as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method MongoDB MBS MongoDB Plugin 25.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Removes all files matching filename and their data chunks from the MongoDB server.

Returns true if successful, including when no files match. Returns false and raises exception if there are invalid arguments or a server or network error.

The items on this page are in the following plugins: MBS MongoDB Plugin.


The biggest plugin in space...