I was trying to store large files using gridfs to a mongodb database, But I kept this same error again and again "TypeError: bucket.openUploadStream is not a function", Let alone the large files I couldn't stream a text due to this error.
const GridFSBucket = require('gridfs-stream');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017').then(()=>
{
console.log('Database connected')
}).catch(()=>
{
console.log("Couldn't connect to DB")
})
const grid = async function ()
{
const bucket = new GridFSBucket(mongoose.connection, { bucketName: 'my-bucket' });
const uploadStream = bucket.openUploadStream()
uploadStream.write("This is the file to upload");
await uploadStream.end();
}
grid();
this is the error: error received