If I understand your question correctly. You are asking. How to cancel or stop having those type of dreams?
Dreams reveal aspects of our psychology that we need to investigate. As long as we have ego and psychological aggregates. Which are not a part of the Divine or our Being. Then we are going to have nightmares and disgusting dreams. Therefore, we need to meditate on our dreams. In order, to comprehend the meaning, the source, and how it is reflected in our own psychology.
I highly recommend reading or listening to the
Dream Yoga Course