Yes.
In fact, i would like to state that in real life, throughout history before usage of firearms becoming common in battlefields, using spears was far more common than most people realize, The idea that spears are in many ways superior weapon compared to swords, mace and other non-spear weapons was no secret to historical generals and warriors.
Spears are very effective and cheap weapons that have been most common weapon of choice among many armies throughout history as mentioned by historical accounts and depictions of armies and battles. For instance look at some of Persian relief or Egyptian relief where you see spears as dominant weapon of choice among most well equpied soldiers in world at that time, despite the fact that we know some variation of swords, mace or club have already existed at the time.
And use of spears contuine well until guns becoming common around the world. For instance look at accounts of Battle of Grunwald, 100 year wars and Siege of Constantinople where we still see mass usage of spears close to popularization of guns.
And even after infantrymen around world start training and relying primarily on guns, armies don't completely stop using spears for quite sometime. For instance take a look at Lances(which i think we can consider as a kind of spear) begin used by cavalierly forces such as Dragoons or Hussars.
So in short, Yes. There is nothing too fictional about an army using only spears to not only hold against but even win against a medieval army of equal discipline and size.
Swords and maces were a popular weapon mostly among cavalry, For instance while most foot soldiers during late antiquity were using only spears as main weapon for battle, Immortals and Azadan of Sasanid Empire were master of using a very wide variety of weapons such as swords, maces, axes, scythes and even chains.
Also, this is my personal opinion without any solid reference: I think because short weapons were better weapons for fighting and self defense in cities where most people lived, people saw swords and maces more often as a combat weapon which is why, such weapon received so much more attention.