Hi I get data from mongoDB and I try insert new data from other function. For some reason I get undefined. What I'm doing is wrong and how can I fix it?
router.post("/list", (req, res, next) => {
const params = req.body;
var results_data = [];
Countability.find()
.populate("user")
.populate("company")
.populate("store")
.exec(function (err, data) {
_.forEach(data, function (value, key) {
results_data[key] = {
_id: value._id,
count: GetCount(10)
};
});
res.status(200).json({ status: 1, result: results_data });
});
});
const GetCount = (id) => {
DataRow.aggregate(
[
{
"$group": {
"_id": "$rowName",
"count": { "$sum": 1 }
}
}
]).exec((err,res) => {
var data = Promise.all([res]);
data.then(function (res) {
return res
})
})
}