There are services that depend on mongodb 3.4 being present. And UniFi is one of them. By removing 3.4.16 as the last 3.4 series mongodb and forcing upgrade to 3.6 when doing a systems upgrade of components like openssl breaks the current system. If the 3.4.16 ebuild was still in place the system patching would complete. Please put back a 3.4.x version until such time that other components no longer need it.
According to https://www.mongodb.com/support-policy version 3.4 will be EOL january 2020,so there is not much reason keeping 4 major versions in portage. Feel free to import into your local overlay. Please ask unifi to migrate to a newer version, 3.4 is really old.