Cannot update db with multer and mongose Cannot update db with multer and mongose mongoose mongoose

Cannot update db with multer and mongose


I have figured out. Use multer with multer-gridfs-storage and grid-fs-stream to read/write photos into the db.

Create a middlewares folder and add these lines of code:

const multer = require("multer");const {GridFsStorage} = require("multer-gridfs-storage");const storage = new GridFsStorage({    url: process.env.CONNECTION_URL,    options: { useNewUrlParser: true, useUnifiedTopology: true },    file: (req, file) => {        const match = ["image/png", "image/jpeg"];        if (match.indexOf(file.mimetype) === -1) {            const filename = `${Date.now()}-any-name-${file.originalname}`;            return filename;        }        return {            bucketName: "photos",            filename: `${Date.now()}-any-name-${file.originalname}`,        };    },});module.exports = multer({ storage });