title: Referencing multiple files upload to DB with node.js
body: <p>I can't understand how to save references (filenames) of multiple files upload to the database using Node.Js. </p>
  
  <p>I'm using blueimp jquery file upload and multer middleware to perform a multiple files upload to the local storage (uploads folder).</p>
  
  <pre><code>&lt;input id="fileupload" type="file" name="images" data-url="/record/edit/#{record.id}" multiple&gt;
  </code></pre>
  
  <p>app.js code:</p>
  
  <pre><code>//using multer to upload files
  const upload_images = upload.fields([{ name: 'featured_img', maxCount: 1 }, { name: 'images', maxCount: 8 }]);
  //...
  app.post('/record/edit/:id',  upload_images, recordController.postUpdate );
  </code></pre>
  
  <p>recordController.js code:</p>
  
  <pre><code>exports.postUpdate = ((req, res, next) =&gt; {
     Record.findById(req.params.id, (err, record) =&gt; {
        if (req.files ) {
  
          console.log('UPLOADED')
          // record.featured_img = req.files['featured_img'][0].filename; //=&gt; working for single file
  
          // Now, how to make it work for multiple files?
          console.log(req.files['images'])
          record.images = "HOW TO SAVE THE INFO OF REQ.FILES TO DB?";
       }
  </code></pre>
  
  <p>console.log output:</p>
  
  <pre><code>UPLOADED
  [ { fieldname: 'images',
      originalname: 'slippry-02.jpg',
      encoding: '7bit',
      mimetype: 'image/jpeg',
      destination: 'C:\\Users\\agaez\\Documents\\sanbox\\nodeApps\\theapp\\uploads',
      filename: '8mdnuacm1469201049450.jpg',
      path: 'C:\\Users\\agaez\\Documents\\sanbox\\nodeApps\\theapp\\uploads\\8mdnuacm1469201049450.jpg',
      size: 49798 } ]
  POST /record/edit/578580b43c7a08601730cc06 302 26.654 ms - 82
  UPLOADED
  [ { fieldname: 'images',
      originalname: 'slippry-03.jpg',
      encoding: '7bit',
      mimetype: 'image/jpeg',
      destination: 'C:\\Users\\agaez\\Documents\\sanbox\\nodeApps\\theapp\\uploads',
      filename: 'yrnnzl9h1469201049467.jpg',
      path: 'C:\\Users\\agaez\\Documents\\sanbox\\nodeApps\\theapp\\uploads\\yrnnzl9h1469201049467.jpg',
      size: 49792 } ]
  </code></pre>
  
  <h3><strong>Update</strong></h3>
  
  <p>I'm using MongoDB as database and mongoose as ODM</p>
  
  <p><strong>More info:</strong> Curretly, I'm using jquery file upload which is making 2 post request when I upload 2 images. Without jquery file uploads it makes 1 post req for all the images uploaded and I get the req.files a unique array (with all the files uploaded). How can I save that info to MongoDB?</p>
  
  <p>recordModel.js</p>
  
  <pre><code>//...
    images: String,
  //...
  </code></pre>