I have fixed it by adding the {useUnifiedTopology: true} connection parameter. So I replaced: with:
{useUnifiedTopology: true}