lib/impl/getForms.js
function getSubmissionStorage(cb) {
      //If no stats are required, don't try and do the map-reduce operation.
      if (options.notStats) {
        return cb();
      }

      // NOTE: this function executes in MongoDB rather than Node.js
      //Need a map-reduce operation to count the files, otherwise would have to load all submissions into memory which is bad.
      var mapFileSizesFunction = function() {
        var key = this.formId;

        var formFields = this.formFields || [];

        //Iterating over all form fields
        for (var formFieldIdx = 0; formFieldIdx < formFields.length; formFieldIdx++) {
          var formField = formFields[formFieldIdx];

          var fieldValues = formField.fieldValues || [];

          //Iterating over all of the field values
          for (var fieldValueIdx = 0 ; fieldValueIdx < fieldValues.length ; fieldValueIdx++) {
            var fieldValue = fieldValues[fieldValueIdx] || {};

            //If the value has a file size associated with it, then emit that file size
            if (fieldValue.fileSize) {
              emit(key, fieldValue.fileSize); // eslint-disable-line no-undef
            }
          }
        }
      };

      // NOTE: this function executes in MongoDB rather than Node.js
      //Function to sum up all of the file sizes for each submission
      var reduceFileSizesFunction = function(formId, fileSizes) {
        var totalFileSizes = 0;

        for (var fileSizeIdx = 0; fileSizeIdx < fileSizes.length ; fileSizeIdx++) {
          totalFileSizes += fileSizes[fileSizeIdx];
        }

        return totalFileSizes;
      };

      logger.debug("getSubmissionStorage", {options: options});

      Promise.race([
        // Don't wait longer than 30 seconds for mongodb mapReduce.
        // Note that it should still complete, but if it's not back in
        // 30 seconds, we continue without it.
        new Promise(resolve => setTimeout(resolve, 30000)),

        //Map-Reduce Operation to count the file sizes.
        connections.databaseConnection.collection('formsubmissions').mapReduce(mapFileSizesFunction, reduceFileSizesFunction, {out : {inline: 1}, verbose:true})
      ])

        .then(out => {
          fileSizesByForm = out && out.results ? out.results : [];
          return cb();
        })

        .catch(err => {
          //If there are no submissions, then the collection does not
          //exist. No need to error out of the request.
          if (err.message.indexOf("ns doesn't exist") > -1) {
            return cb();
          } else {
            return cb(err);
          }
        });
    }
function getSubmissionStorage(cb) {
      //If no stats are required, don't try and do the map-reduce operation.
      if (options.notStats) {
        return cb();
      }

      // NOTE: this function executes in MongoDB rather than Node.js
      //Need a map-reduce operation to count the files, otherwise would have to load all submissions into memory which is bad.
      var mapFileSizesFunction = function() {
        var key = this.formId;

        var formFields = this.formFields || [];

        //Iterating over all form fields
        for (var formFieldIdx = 0; formFieldIdx < formFields.length; formFieldIdx++) {
          var formField = formFields[formFieldIdx];

          var fieldValues = formField.fieldValues || [];

          //Iterating over all of the field values
          for (var fieldValueIdx = 0 ; fieldValueIdx < fieldValues.length ; fieldValueIdx++) {
            var fieldValue = fieldValues[fieldValueIdx] || {};

            //If the value has a file size associated with it, then emit that file size
            if (fieldValue.fileSize) {
              emit(key, fieldValue.fileSize); // eslint-disable-line no-undef
            }
          }
        }
      };

      // NOTE: this function executes in MongoDB rather than Node.js
      //Function to sum up all of the file sizes for each submission
      var reduceFileSizesFunction = function(formId, fileSizes) {
        var totalFileSizes = 0;

        for (var fileSizeIdx = 0; fileSizeIdx < fileSizes.length ; fileSizeIdx++) {
          totalFileSizes += fileSizes[fileSizeIdx];
        }

        return totalFileSizes;
      };

      logger.debug("getSubmissionStorage", {options: options});

      Promise.race([
        // Don't wait longer than 30 seconds for mongodb mapReduce.
        // Note that it should still complete, but if it's not back in
        // 30 seconds, we continue without it.
        new Promise(resolve => setTimeout(resolve, 30000)),

        //Map-Reduce Operation to count the file sizes.
        connections.databaseConnection.collection('formsubmissions').mapReduce(mapFileSizesFunction, reduceFileSizesFunction, {out : {inline: 1}, verbose:true})
      ])

        .then(out => {
          fileSizesByForm = out && out.results ? out.results : [];
          return cb();
        })

        .catch(err => {
          //If there are no submissions, then the collection does not
          //exist. No need to error out of the request.
          if (err.message.indexOf("ns doesn't exist") > -1) {
            return cb();
          } else {
            return cb(err);
          }
        });
    }
function getSubmissionStorage ( cb ) { //If no stats are required, don't try and do the map-reduce operation. if ( options . notStats ) { return cb ( ) ; } // NOTE: this function executes in MongoDB rather than Node.js //Need a map-reduce operation to count the files, otherwise would have to load all submissions into memory which is bad. var mapFileSizesFunction = function ( ) { var key = this . formId ; var formFields = this . formFields || [ ] ; //Iterating over all form fields for ( var formFieldIdx = 0 ; formFieldIdx < formFields . length ; formFieldIdx ++ ) { var formField = formFields [ formFieldIdx ] ; var fieldValues = formField . fieldValues || [ ] ; //Iterating over all of the field values for ( var fieldValueIdx = 0 ; fieldValueIdx < fieldValues . length ; fieldValueIdx ++ ) { var fieldValue = fieldValues [ fieldValueIdx ] || { } ; //If the value has a file size associated with it, then emit that file size if ( fieldValue . fileSize ) { emit ( key , fieldValue . fileSize ) ; // eslint-disable-line no-undef } } } } ; // NOTE: this function executes in MongoDB rather than Node.js //Function to sum up all of the file sizes for each submission var reduceFileSizesFunction = function ( formId , fileSizes ) { var totalFileSizes = 0 ; for ( var fileSizeIdx = 0 ; fileSizeIdx < fileSizes . length ; fileSizeIdx ++ ) { totalFileSizes += fileSizes [ fileSizeIdx ] ; } return totalFileSizes ; } ; logger . debug ( "getSubmissionStorage" , { options : options } ) ; Promise . race ( [ // Don't wait longer than 30 seconds for mongodb mapReduce. // Note that it should still complete, but if it's not back in // 30 seconds, we continue without it. new Promise ( resolve => setTimeout ( resolve , 30000 ) ) , //Map-Reduce Operation to count the file sizes. connections . databaseConnection . collection ( 'formsubmissions' ) . mapReduce ( mapFileSizesFunction , reduceFileSizesFunction , { out : { inline : 1 } , verbose : true } ) ] ) . then ( out => { fileSizesByForm = out && out . results ? out . results : [ ] ; return cb ( ) ; } ) . catch ( err => { //If there are no submissions, then the collection does not //exist. No need to error out of the request. if ( err . message . indexOf ( "ns doesn't exist" ) > - 1 ) { return cb ( ) ; } else { return cb ( err ) ; } } ) ; }
Function for getting the current submission storage.

Submission Storage = formsubmissions + fileStorage.chunks + fileStorage.files
Function for getting the current submission storage .