I have the following code, in which I'm using GridFS-stream to upload an image to my mongodb database that's called "test".
const formidableMiddleware = require('express-formidable');
var GridFS = Grid("test", mongoose.mongo);
app.use(formidableMiddleware({multiples:true}));
// for a driver/user to new a product
app.post('/api/newRequest', (req, res) => {
const form = new IncomingForm();
const images = req.files.image;
var writestream = GridFS.createWriteStream({
filename: images[0].name
});
writestream.on('close', function (file) {
console.log("WRITESTREAM CLOSED");
});
});
Upon sending /api/getRequest from the client, I get the following error at line var writestream...
:
[0] (node:15733) DeprecationWarning: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead
[0] TypeError: Cannot read property 'readPreference' of undefined