Mamdani is on course to win the Democratic primary after Tuesday's election, beating predictions.