i have leads of array, i need to catch the activityFor from array and find the data from mongo database by using mongoose and replace that data, when i am doing with map function i am getting array of promise
const newData = leads.map(async (data) => {
_activityFor = await User.find({ _id: { $in: data.activityFor } }).select(
" name employeeId"
);
data.activityFor = _activityFor;
console.log("data", data);
return data;
});
console.log("newData", newData);
output:
newData [
Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> }
]
please let me know how can i get actual array of data instead of promise array
And if I am using like this also get the same result
const newData = leads.map(function (obj) {
return User.find({ _id: { $in: obj.activityFor } })
.select(" name employeeId")
.exec()
.then((dd) => {
obj.activityFor = dd;
return obj;
});
});
console.log("newData", newData);