File not found error when using GridFSBucket openDownloadStream File not found error when using GridFSBucket openDownloadStream mongoose mongoose

File not found error when using GridFSBucket openDownloadStream


According to the API doc here, in order to use filename as argument you should use

openDownloadStreamByName(filename, options)

not openDownloadStream. openDownloadStream takes id of the file.


Another possible explanation for this, if you're already calling openDownloadStream and still experiencing the FileNotFound error, and you are 100% the id is correct, is that you didn't pass an ObjectId type.

In my case, I was passing an id string instead of an id as an ObjectId.

bucket.openDownloadStream(mongoose.Types.ObjectId(id));

vs

bucket.openDownloadStream(id);