Answers for "what does results.push({}) nodejs mean"

0

what does results.push({}) nodejs mean

const mongoose = require('mongoose');
    var data = async function () {
         var array = [];
         const finalResults = await new Promise((resolve, reject) => {
            mongoose.connection.collection("organizations").find({}).toArray(function(err, result) {
              resolve(result);
           });
      });

     for(var i = 0; i < finalResults.length; i++)
     {
          var a = finalResults[i].name;
           array.push(a);
      }
        return array;
    };

    module.exports = {
        data: data,
    };
Posted by: Guest on April-17-2020
0

what does results.push({}) nodejs mean

const mongoose = require('mongoose');

var data = async function () {

    const array = await mongoose.connection.collection("organizations").find({}).toArray(function(err, result) {
        if (err) throw err;
        return result.map(r => r.name);
    });

    console.log(array); //this shows only [] meaning that the array is now empty.
                        //this is shown in the log before the first log
    return array;
};

module.exports = {
    data: data,
};
Posted by: Guest on April-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language