Moved mongodb code into model