this is a bit of a beginners question. I need to query/find multiple elements from an array in my mongodb database. If at least one element pass an if-statement i want to set an error variable to true. Unfortunately because of the async call the variable will be returned early and remains false. Can you give me a hint on how to achieve this. Here is the code so far:
objects = ["a","b","c"]
for (object of objects) {
loanObject.findById(object._id)
.then((object) => {
if (object) {
isError = true
}
})
.catch(err => console.log(err))
}
console.log(isError) // returns false while should be true