I'm currently using a forEach loop that iterates through an array of emails that I'm using to update and set/save the data that I'm sending over via a post request.
This is my current code:
app.post('/register/register', function(req, res){
var emails = ['[email protected]', '[email protected]', '[email protected]']
emails.forEach(function(element){
User.update(
{email: element}, {$set: {team: req.body}}
, function(err, user){
})
})
res.sendStatus(200);
})
This code works but I can't help but feel that it is really poorly written. Is there something in mongoDB that will allow me to find all the documents in the array emails and I can update it all at once with the data instead of looping through each item and saving it that way?
Thank you.