Solving the "The following signatures were invalid KEYEXPIRED" apt-get update linux error

The Error

My travis CI pipeline builds randomly starting failing recently, with the following exception:

Reading package lists...
W: GPG error: precise/mongodb-org/3.4 Release: The following signatures were invalid: KEYEXPIRED 1578250443
E: The repository ' precise/mongodb-org/3.4 Release' is not signed.
The command "sudo apt update" failed and exited with 100 during 

The mongoDB certificates had expired!

The Solution

Luckily, I stumbled upon a simple, one-line command that updates all the expired keys from the ubuntu keyserver:

sudo apt-key list | \
 grep "expired: " | \
 sed -ne 's|pub .*/\([^ ]*\) .*|\1|gp' | \
 xargs -n1 sudo apt-key adv --keyserver hkp:// --recv-keys

This command first lists all the keys in the sytem, then narrows this list down to only expired keys. The expired keys are then extracted and updated.

Thanks to Peter and dlopatin for this solution.