Postgresql refactor code to Mongoid MongoDB database