title: Insert file with form data in mongodb using express
body: <p>I was trying to upload a .mp4 file to my mongodb database with some other information. I can save the file using multer and gridfs. The code i am using for this:</p>
  
  <pre><code>// Create storage engine
  const storage = new GridFsStorage({
      url: mongoURI,
      file: (req, file) =&gt; {
          return new Promise((resolve, reject) =&gt; {
              crypto.randomBytes(16, (err, buf) =&gt; {
                  if (err) {
                      return reject(err);
                  }
                  const filename = buf.toString('hex') + path.extname(file.originalname);
                  const fileInfo = {
                      filename: filename,
                      bucketName: 'vid'
                  };
                  resolve(fileInfo);
              });
          });
      }
  });
  const upload = multer({ storage });
  
  router.post('/upload', upload.single('video'), (req, res) =&gt; {
      res.json({ file: req.file });
      // res.redirect('/');
  });
  </code></pre>
  
  <p>And for uploading file data into db i'm doing this:</p>
  
  <pre><code>//ADD VIDEO
  router.post('/addVideo', (req,res) =&gt; {
      var newVideo = new Video();
  
      newVideo._courseId = req.body.courseId;
      newVideo._chapterId = req.body.chapterId;
      newVideo.name = req.body.name;
      newVideo.des = req.body.des;
  
      newVideo.save((err,note) =&gt; {
          if(err){
              res.status(404).send({err: "Something went wrong"})
          } else {
              res.status(200).send({err: "Your note has been added!!"})
          }
      })
  })
  </code></pre>
  
  <p>Both parts are working well but i have to make just one request for addVideo. In addVideo, name should be same as video name by which it is saved. I don't know how to merge both code for this functionality. Thank you.</p>