I am working on a route with the following code :
router.put("/:id", upload.single('doc_upload'), async(req,res)=>{
try{
const updatedUser = await User.findOneAndUpdate({ "client._id": req.params._id,"clients.documents._id":req.body.doc_id},
{"$set":{"clients.$[clientFilter].documents.$[documentFilter].status":"uploaded"}},
{"arrayFilters":[
{"clientFilter._id":req.params.id},
{"documentFilter._id":req.body.doc_id}
]} ,
);
for (i=0; i < updatedUser.clients.length; i++) {
if (updatedUser.clients[i]._id == req.params.id) {
for (j=0; j < updatedUser.clients[i].documents.length; j++) {
console.log("this is the status of all my docs" + updatedUser.clients[i].documents[j].status)
}
}
}
res.send(req.file)
} catch(err){
res.status(500).json(err);
}
In this code, the status of the documents is updated from "pending" to "uploaded" after searching for a user. However, the console is still showing "pending" for all documents even after the update. I need help in figuring out how to update the user first and then display the updated status of the documents. Any suggestions?