Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

MongoDB.GridFS.Write

Writes a container value as file to GridFS.

Component Version macOS Windows Linux Server iOS SDK
MongoDB 16.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "MongoDB.GridFS.Write"; MongoDBRef; Container { ; Options } )   More

Parameters

Parameter Description Example Flags
MongoDBRef The reference number for the mongo connection. $MongoDB
Container The container value to pass. MyTable::Photo
Options A JSON with options.
May include md5, filename, contentType, chunkSize, aliases, metadata values.
Optional

Result

Returns OK or error.

Description

Writes a container value as file to GridFS.

Examples

Store container in MongoDB:

Set Variable [ $r ; Value: MBS( "MongoDB.GridFS.Open"; $Mongo; "test" ) ]
If [ MBS("IsError") ]
    Set Variable [ $x ; Value: MBS( "MongoDB.Release"; $Mongo ) ]
    Show Custom Dialog [ "Failed to open gridfs." ; $r ]
    Exit Script [ Text Result: ]
End If
#
Set Variable [ $image ; Value: test::Photo ]
If [ IsEmpty ( $image ) ]
    Show Custom Dialog [ "Please add something into cont…" ]
Else
    # writes to database. Will use file name from container
    Set Variable [ $r ; Value: MBS( "MongoDB.GridFS.Write"; $Mongo; $image; "{}" ) ]
    If [ MBS("IsError") ]
        Set Variable [ $x ; Value: MBS( "MongoDB.Release"; $Mongo ) ]
        Show Custom Dialog [ "Failed to drop gridfs." ; $r ]
        Exit Script [ Text Result: ]
    End If
    #
    Show Custom Dialog [ "File written" ; $r ]
End If

Store photo with custom file name and content type:

MBS( "MongoDB.GridFS.Write"; $Mongo; $image; "{\"filename\": \"test.jpg\", \"contentType\": \"image/jpeg\"}" )

See also

Release notes

  • Version 16.3
    • Added GridFS functions for MongoDB functions: MongoDB.GridFS.Close, MongoDB.GridFS.Drop, MongoDB.GridFS.Find, MongoDB.GridFS.FindOne, MongoDB.GridFS.FindOneByFileName, MongoDB.GridFS.GetChunks, MongoDB.GridFS.GetFiles, MongoDB.GridFS.Open, MongoDB.GridFS.Read, MongoDB.GridFS.Remove, MongoDB.GridFS.RemoveByFileName and MongoDB.GridFS.Write.

This function checks for a license.

Created 28th May 2026, last changed 28th May 2026


MongoDB.GridFS.RemoveByFileName - MongoDB.HasCollection