使用Nodejs将文件存储在mongodb中

我将文件保存在服务器的FS上,现在我想将它们保存在MongoDB中(为了更容易备份和备份)。我想存储最大4-5Mb的文件,我尝试用缓冲types的mongoose保存它们。我成功保存了他们,并检索他们,但我注意到,当我保存和检索像4或5Mb的文件显着缓慢的性能。

我的模式:

let fileSchema = new Schema({ name: {type: String, required: true}, _announcement: {type: Schema.Types.ObjectId, ref: 'Announcements'}, data: Buffer, contentType: String }); 

我如何从expressjs服务器中检索它们:

  let name = encodeURIComponent(file.name); res.writeHead(200, { 'Content-Type': file.contentType, 'Content-Disposition': 'attachment;filename*=UTF-8\'\'' + name }); res.write(new Buffer(file.data)); 

我的问题是我应该使用一些zlib压缩function,如“deflate”来压缩缓冲区,然后将它们保存到mongodb中,然后在发送到客户端之前解压二进制文件? 这会使整个过程更快吗?我错过了什么?