The men walked into the Wee Dram store in Sinclair Drive, Battlefield and demanded money while attempting to smash the glass partition with bricks.
The incident happened at around 4.30pm on Sunday.
The men fled with a two-figure sum of cash, leaving the shopkeeper and the child uninjured but distressed.
Detectives are hunting the pair and have urged anyone with information to come forward.
Detective Sergeant Craig Warren said: "This has been a very frightening experience and unfortunately a young child witnessed the incident which was clearly distressing.
"This is quite a busy thoroughfare and at that time of the day there would have been people around, so I'm appealing directly to them to get in touch with us as they may have seen something."