Port a fix from the mongo driver.