I presume this is a silly question But I can't find the answer. If I iterate over collection in mongodb how do I put the result of each iteration into an array? Code below does not work
mongoClient.connect(url, async (err,db) => {
payments = await db.collection("accounting-payment").find({})
})
let usersInPayments = [];
payments.forEach(async (doc) => {
return usersInPayments.push( await doc.createInfo.userId)
}, (err) => console.log(err))