| Components | All | New | MacOS | Windows | Linux | iOS | ||||
| Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old | |
MongoDB.GridFS.FindOneByFileName
Finds the first file matching the filename specified.
| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
| MongoDB | 16.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
MBS( "MongoDB.GridFS.FindOneByFileName"; MongoDBRef; Filename ) More
Parameters
| Parameter | Description | Example |
|---|---|---|
| MongoDBRef | The reference number for the mongo connection. | $MongoDB |
| Filename | The file name to find. | "test.jpg" |
Result
Returns JSON object, empty or error.
Description
Finds the first file matching the filename specified.If there is an error, we return it; if there is no error but no matching file is found, empty result 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.
Returns details about the file as JSON.
Examples
Find file by file name:
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 [ $r ; Value: MBS( "MongoDB.GridFS.FindOneByFileName"; $Mongo; "test.jpg" ) ]
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 found" ; $r ]
Example result:
{ "id": { "$oid": "6a1836306f6e4b6f9e03f46d" }, "length": 469744, "uploadDate": 1779971632057, "chunkSize": 261120, "filename": "test.jpg" }
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 [ $r ; Value: MBS( "MongoDB.GridFS.FindOneByFileName"; $Mongo; "test.jpg" ) ]
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 found" ; $r ]
Example result:
{ "id": { "$oid": "6a1836306f6e4b6f9e03f46d" }, "length": 469744, "uploadDate": 1779971632057, "chunkSize": 261120, "filename": "test.jpg" }
See also
- IsError
- MongoDB.GridFS.Find
- MongoDB.GridFS.FindOne
- MongoDB.GridFS.Open
- MongoDB.GridFS.RemoveByFileName
- MongoDB.Release
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