Refactor Document#save

Extract Insert and Update commands.