const arr = [];
const res=Fruit.find({});
res.cursor().on('data',function(fruit){
arr.push(fruit);
});
console.log(arr);
I have written the above code. I want to fill my array with fruits that i get from find function of mongoose. But if I am writing like this, then what i get is an empty array on printing.
How to solve this ?
I searched up for different forums online but i was not able to solve the problem.