Replace database queries in repositories with Morphia

This needs the license.