How does mongodb pass data to external variables when traversing data using foreach queries and cursors?

has the following code:

let result = {
      data: {
        values: [],
      }
    };

    try {
      let baseInfo = await baseinfoModel.getSystemInfo();
      if (baseInfo === null) {
        return null;
      } else {
        baseInfo.forEach(function (doc) {
          result.data.values.push({
            objectid: doc._id,
            system: doc.system,
          });
        }, function (err) {
          if (err) {
            throw err;
          }
        })
        
        return result;
      }
    } catch (err) {
      throw err;
    }

here comes the problem: result data is stored in forEach, but the external definition of result has not changed. How can you pass forEach data to external variables?

Mar.01,2021

this can be changed to the outer result variable. I can't tell because I don't know exactly what's going on in getSystemInfo () . First make sure whether you are going if or else .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-16de630-88ea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-16de630-88ea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?