1const mongoose = require('mongoose');
2 var data = async function () {
3 var array = [];
4 const finalResults = await new Promise((resolve, reject) => {
5 mongoose.connection.collection("organizations").find({}).toArray(function(err, result) {
6 resolve(result);
7 });
8 });
9
10 for(var i = 0; i < finalResults.length; i++)
11 {
12 var a = finalResults[i].name;
13 array.push(a);
14 }
15 return array;
16 };
17
18 module.exports = {
19 data: data,
20 };
1const mongoose = require('mongoose');
2
3var data = async function () {
4
5 const array = await mongoose.connection.collection("organizations").find({}).toArray(function(err, result) {
6 if (err) throw err;
7 return result.map(r => r.name);
8 });
9
10 console.log(array); //this shows only [] meaning that the array is now empty.
11 //this is shown in the log before the first log
12 return array;
13};
14
15module.exports = {
16 data: data,
17};