The console in the end returns empty array. The console runs before ids.map function finishes
var ids = [];
var allLync = []
var user = await User.findOne(args.user)
ids.push(user._id)
user.following.map(x => {
ids.push(x)
})
ids.map(async x => {
var lync = await Lync.find({ "author": x })
lync.map(u => {
allLync.push[u]
})
})
console.log(allLync)
What am I doing wrong?
lync- try addingconsole.log(lync)to see whatLync.find({ "author": x })is returning to you - by the way, that is a really bad use of.map- the way you wrote that, you may as well use.forEach.maphere since they need the promises back to await them before thelog.mapare not being actually used - I said the way he uses .map he may as well use .forEach .... but .map is the right method if it is used correctly