I have an array with multiple values which need to be used as queries to search a collection. I am not sure of a way of doing this using one route. for example:
router.get('/', ensureAuthenticated, (req, res) => {
let ArrayOfIds = [id1, id2, id3]
Movie.find({user: req.user.id}).then(items => {
//Something along this lines
items.subscriptions.forEach(subscription => {
Movie.find({user: subscription})
//This wont work beacuse of the callback promise
.then(movies => {
items.push(movies)
})
})
res.render('index/home',
{pageName: 'Movies', items: items})
.catch(err => console.log(err));
});
})
I want to search the same collection (Movie) for each id and add it to the items object. Doing it with a for loop seems to create a set header error. Any ideas?