Currently I'm struggeling with querying data from a MongoDB GridFS
by using the filename.
Current situation
I'm uploading data to the MongoDB by using a GridFSBucket
and UploadFromBytesAsync
which returns an ObjectId
for referencing the data and takes a filename
as parameter.
The Problem
The oposit of UploadFromBytesAsync
is DownloadAsBytesAsync
which should be used for querying the data from GridFS
. But this method only accepts an ObjectId
and not the unique filename
which is also passed when using UploadFromBytesAsync
. But I want to query the data by using the filename
.
Possible solution
My Idea was, to create a collection, which stores the GridFS ObjectId
and GridFS filename
, to map them. So when querying data, i will search for the filename
in the collection and then using the ObjectId
to get the bytes from GridFS
. The filename
property would also get an index.
Or should I directly query from GridFS
using the unique filename
? And is the filename
indexed than?
EDIT!
Oh, i think the problem is solved by using DownloadAsBytesByName
.
Thank you very much!