Answer the question
In order to leave comments, you need to log in
How to perform findOneAndUpdate on an array of _id?
There is an array of IDs
How to execute for each element from the array and then return a response to the client about a successful operation? Should I do a cycle? Now I have something like thisconst array = ['c454tv354tv5', 'vgrge45t435tv3']
findOneAndUpdate
exports.addArticle = (req, res, next) => {
const newArticle = new Article(req.body)
newArticle
.save()
.then(article => {
Tag
.findOneAndUpdate({ _id: article.tags }, {$push: {"articles": article._id}}, {new: true})
.then(data => {
return res.status(201).json({
status: 'OK',
data
})
})
})
.catch(err => {
return next(err)
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question