How does one handle a bottleneck of enemies in a doorway?

As a new DM I’m still learning how to control the monsters in a battle. A situation came up last game and although it was fine and fun, I wonder if there are better strategies for a DM to avoid a bottleneck in a doorway.

Scenario: PCs were up against a door deciding whether they should go in. Hobgoblins on the other side of the door open it and an encounter ensues. However, the encounter is basically the PC at the door trading blows with the NPC at the door, while their respective allies in the back try to shoot over their friends’ heads. Although you can move through an ally’s space, you can’t occupy an ally’s square. This leads me to assume that you can’t move in to an ally’s square, attack from it, and move back out of the square (though please correct me if I’m wrong).

This scenario and understanding of the rules brings me to my question.

What tactics can a DM use in a combat scenario like the one above to make sure that the NPCs are all contributing to the battle? Especially if they have no ranged weapons, is there a way that they can all try to attack?