What I understand is that you want the chat array to become:
That is you want the 2nd element, that is chat[ 1 ], to the answer object because the question object is present and the answer is not.
If that is the case, look at this playground. It uses the $ operator to update the element specified by $elemMatch to specify an element that has a question but no answer.
It will not be necessarily the last, in fact it is the first that matches the $elemMatch.