Is there a link between digestion and nightmares?
A nightmare is basically an alarm; typically your subconcious mind trying to wake you. Nightmares often occur when you are experiencing pain or discomfort (like needing to use the bathroom). 

Dreams are a way of sorting through questions in a "what if" sort of way. When it comes to a nightmare, you are in a panic-situation, often without a solution, or where a "logical" solution is unsuccessful.