mongodb plugin: Refactor the "handle_opcounters" function.