Refactor from mongo to mysql