Sunday, 21 May 2017

Promise/async-await with mongoose, returning empty array

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?



via ANKIT HALDAR

No comments:

Post a Comment