| Components | All | New | MacOS | Windows | Linux | iOS | ||||
| Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old | |
MongoDB.GridFS.FindOne
Find the first GridFS file matching filter.
| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
| MongoDB | 16.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
MBS( "MongoDB.GridFS.FindOne"; MongoDBRef; filter { ; opts } ) More
Parameters
| Parameter | Description | Example | Flags |
|---|---|---|---|
| MongoDBRef | The reference number for the mongo connection. | $MongoDB | |
| filter | The JSON with filter options. | "{}" | |
| opts | Options as JSON. Various query options, including sort order and which fields to return. |
Optional |
Result
Returns JSON object, empty or error.
Description
Find the first GridFS file matching filter.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 one by name:
Set Variable [ $r ; Value: MBS( "MongoDB.GridFS.FindOne"; $Mongo; "{\"filename\": \"test.jpg\"}"; "{}" ) ]
Example result:
{ "id": { "$oid": "6a18386e6f6e4b6f9e03f480" }, "length": 469744, "uploadDate": 1779972206774, "chunkSize": 261120, "filename": "test.jpg", "contentType": "image/jpeg" }
Example result:
{ "id": { "$oid": "6a18386e6f6e4b6f9e03f480" }, "length": 469744, "uploadDate": 1779972206774, "chunkSize": 261120, "filename": "test.jpg", "contentType": "image/jpeg" }
Find one by file size:
Set Variable [ $r ; Value: MBS( "MongoDB.GridFS.FindOne"; $Mongo; "{\"length\": 469744}"; "{}" ) ]
Example result:
{ "id": { "$oid": "6a18386e6f6e4b6f9e03f480" }, "length": 469744, "uploadDate": 1779972206774, "chunkSize": 261120, "filename": "test.jpg", "contentType": "image/jpeg" }
Example result:
{ "id": { "$oid": "6a18386e6f6e4b6f9e03f480" }, "length": 469744, "uploadDate": 1779972206774, "chunkSize": 261120, "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