added recursive function
moved mongo code into own file for better organization