Sayyiduna Ali bin Abi Talib (may Allah be pleased with him) narrates: When the Prophet (peace and blessings be upon him) entered the mosque, he would say: "O Allah, open for me the doors of Your mercy." (And when he) came out (of the mosque), he would say: "O Allah, open for me the doors of Your bounty."
Abu Ya'la recorded it; its chain contains Salih bin Musa, who is matruk al-hadith (abandoned in hadith).
Hadith Referenceمجمع الزوائد ومنبع الفوائد / كتاب الصلاة / 2096