Mollies and goldfish do not belong in the same aquarium. These fish need very different water chemistry, can infect each other with diseases and may have a predator/prey relationship. Mollies and goldfish need very different fish tanks.
All fish have adapted to the water conditions of their home range. Mollies come from a warm part of the tropics in Central America and need warm water to thrive. In aquariums, mollies do their best between 77 and 82 degrees Fahrenheit. Meanwhile, goldfish come from temperate and subtropical regions of China. Because of this, goldfish need colder temperatures -- between 68 and 72 degrees. While mollies can tolerate colder water and goldfish can survive in warmer temperatures, neither fish can really thrive in the others' safe range. Outside of their ideal temperature range, fish get stressed and more prone to disease.
Since goldfish and mollies come from very different regions, they have adapted to different suites of parasites and diseases. As such, goldfish have a tolerance for diseases that can kill mollies and vice versa. So goldfish and mollies should not share an aquarium, since they can readily infect each other with various diseases.
Under ideal conditions, goldfish can grow at least eight inches long -- sometimes more than a foot. Several species of mollies show up in the aquarium trade, including several hybrids. This means mollies have a size range between 2 and 6 inches. So a larger goldfish could easily eat a smaller molly if the two fish were unfortunate enough to share an aquarium, especially if the molly is not fully grown or comes from one of the smaller species.
Additionally, mollies need salt in their aquarium water in order to thrive. Though mollies can survive without salt, mollies with salt will be healthier and look better. However, goldfish come from pure, fresh water with very little, if any, salt. The levels of salt that mollies need to stay healthy can stress out a goldfish.