Fix a bug when deleting document