0

I'm trying to add new values into an array of objects and then returning the entire object, with the new values, to the client.

I've already tried using async/await and promises, though possibly doing that wrong. I did also read that forEach isn't async await so I tried using map too but that didn't work for me.

 // results
    const userPromise = new Promise((resolve, reject) => {
        results.forEach((pyUser) => {
            console.log(pyUser);
            // For each user attempt to look up associated data
            User.findOne({ _id: pyUser.id }, (err, user) => {
                if (user){
                    pyUser.address= 'Test address';
                }
            });
        });
        resolve();
    }).then(
        console.log(results)
    // Send results
    res.send(results)
    ).catch(
        console.log('Ooooops...')
    )

I'm hoping that results that are being sent back will include the new address property.

Stephanie Parker
  • 313
  • 3
  • 11

0 Answers0