Skip to content

GridFS.delete returns DeleteResult #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

GridFS.delete returns DeleteResult #424

wants to merge 1 commit into from

Conversation

drhagen
Copy link

@drhagen drhagen commented Sep 15, 2019

pymongo.Collection.delete_one returns a DeleteResult object which, among other things, provides the deleted_count attribute telling whether or not anything was actually deleted by the call. However, gridfs.GridFS.delete returns nothing regardless if a document is deleted. This PR changes the behavior of GridFS to more closely follow Collection by returning the DeleteResult from the underlying call to delete the document index.

@ShaneHarvey
Copy link
Member

Thanks for the pull. The implementation seems fine but GridFs is pymongo's old API for gridfs. GridFSBucket is the new API which is implemented according to the GridFS spec.

The newer GridFSBucket.delete method raises a NoFile exception when the file does not exist. May I suggest using the newer API instead because it already supports your use-case?

@mongodb mongodb deleted a comment from rathisekaran Nov 11, 2019
@ShaneHarvey
Copy link
Member

ShaneHarvey commented Nov 11, 2019

Hi @drhagen, we have decided not to add this feature to the old GridFS api because the newer GridFSBucket.delete method already supports it. Please let us know if you have any issues using GridFSBucket:

import gridfs
my_db = MongoClient().test
fs = gridfs.GridFSBucket(my_db)
try:
    fs.delete(file_id)
except gridfs.errors.NoFile:
    # file_id did not exist.
    pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants