The Messenger of Allah ﷺ said, "When one of you sees a dream that he dislikes, let him spit to his left three times, seek refuge in Allah from Satan three times, and turn over from the side he was lying on."
حدثنا محمد بن رمح المصري أنبأنا الليث بن سعد عن أبي الزبير
عن رسول الله ﷺ أنه قال إذا رأى أحدكم الرؤيا يكرهها فليبصق عن يساره ثلاثا وليستعذ بالله من الشيطان ثلاثا وليتحول عن جنبه الذي كان عليه
Muslim reported it in the Book of Dreams, chapter on dreams being from Allah and being a part of prophethood, hadith no. 2262/6, from Ibn Ramh, with this wording.