Node.js 如何使用gridfs在MongoDB中存储ZIP文件
要在我的MongoDB数据库中存储ZIP文件,它们的大小超过16MB 我尝试使用mongoose gridfs,但无法取回文件Node.js 如何使用gridfs在MongoDB中存储ZIP文件,node.js,mongodb,mongoose,gridfs,Node.js,Mongodb,Mongoose,Gridfs,要在我的MongoDB数据库中存储ZIP文件,它们的大小超过16MB 我尝试使用mongoose gridfs,但无法取回文件 mongoose.connect('mongodb://localhost:27017/cache').then(() => { const { model: Attachment } = gridfs({ collection: 'attachments', model: 'Attachment', mongooseConnectio
mongoose.connect('mongodb://localhost:27017/cache').then(() => {
const { model: Attachment } = gridfs({
collection: 'attachments',
model: 'Attachment',
mongooseConnection: mongoose.connection
});
const readStream = fs.createReadStream('./test.zip');
const options = ({ filename: 'cache.zip', contentType: 'application/zip' });
Attachment.write(options, readStream, (error, file) => console.log(error,file) );
});
它返回一个对象id,例如-5cc2d68d9572233b3004952a
但是我试着去拿那个文件
Attachment.readById('5cc2d68d9572233b3004952a', (err, buffer ) => console.log(buffer));
我没有定义
在我的MongoDB中(屏幕)