Self-described democratic socialist Zohran Mamdani has won the election to be the next mayor of New York City.