Extract ``format`` functionality

Make it possible to extend ``format`` functionality. It is useful when required to add additional fields to the generated mongo document.