Here i am receiving a set of token in csv texts and every token belongs a document in monogdb. My logic is to get the documents token wise and return them as an array to the front end .
Here I have done this but its returning an empty error instead of array of objects.
var helps = [];
const token_list = req.body.token_list;
let splittedtoken = token_list.split(",");
splittedtoken.shift();
console.log(splittedtoken);
splittedtoken.forEach(token => {
Help.find({ 'token': token }, (err, result) => {
if (result) {
helps.push(result[0])
}
});
console.log(helps);
})`
i am unable to solve it , any kind suggestions are heartly welcome . Thanks
Helpis your db collection. It's async butforEachis not async