I have uploaded a 400Mb zip file to MongoDB using GridFS. I then try to donwnload it using the following code:
let mongoGridFsBucket = new mongodb.GridFSBucket(Mongoose.connection.db, {
chunkSizeBytes: 1024,
bucketName
})
let gridFsDownloadStream = mongoGridFsBucket.openDownloadStreamByName(filename)
gridFsDownloadStream.on('error', console.error)
gridFsDownloadStream.on('end', function() {
console.info('downloaded')
})
gridFsDownloadStream.pipe(fs.createWriteStream('/local/path/to/downloaded.zip'))
and get this Error:
MongoServerError: Executor error during find command :: caused by :: Sort exceeded memory limit of 33554432 bytes, but did not opt in to external sorting.
The above code works fine for smaller files (e.g. 9Mb files), I’ve already tested that successfully.
However in this case the file is too big. I looked for a solution online and apparently there is some allowDiskUse
flag that I need to set somewhere but I don’t know where and how .
There is no place in the above code where I could set this allowDiskUse
to true
so I don’t know what else to do to make this work.