DRIVERS-2807 Update GridFS spec to add delete_by_name and rename_by_name#1702
DRIVERS-2807 Update GridFS spec to add delete_by_name and rename_by_name#1702
delete_by_name and rename_by_name#1702Conversation
renameByName and deleteByName
renameByName and deleteByNamedelete_by_name and rename_by_name
delete_by_name and rename_by_namedelete_by_name and rename_by_name
source/gridfs/gridfs-spec.md
Outdated
| **Implementation details:** | ||
|
|
||
| Drivers MUST first find the `_id` field of all files collection documents with the given filename. Drivers MUST then | ||
| delete all chunks with `files_id` in the found ids that was just deleted. Drivers MUST then delete all files collection |
There was a problem hiding this comment.
Wouldn't we want to delete the files documents first and then the chunks? Doing the opposite increases the chance of reading a phantom corrupt file. This is the same reason we always upload the chunks before saving the files document.
There was a problem hiding this comment.
You are correct. Files should be deleted before chunks to ensure there is no partial files. But if the operation that deletes chunks fails, then there is orphan chunks.
Spec updated.
c1ce40a to
841a729
Compare
source/gridfs/gridfs-spec.md
Outdated
|
|
||
| Drivers MUST first find the `_id` field of all files collection documents with the given filename. Drivers MUST then | ||
| delete all files collection documents with the found ids. Drivers MUST then delete all chunks with `files_id` in the | ||
| found ids that was just deleted. |
There was a problem hiding this comment.
ids that was just deleted. -> ids that were just deleted.
Or use client.bulk_write() to delete both in one command :). We can leave that as a future optimization.
There was a problem hiding this comment.
Or use client.bulk_write() to delete both in one command :). We can leave that as a future optimization.
This would require server version 8.0 with the new client bulk write API to perform operations on both collections.
delete_by_name and rename_by_namedelete_by_name and rename_by_name
ShaneHarvey
left a comment
There was a problem hiding this comment.
LGTM after the small grammar fix.
| To rename all revisions of a stored file with the specified filename, drivers SHOULD provide the method | ||
| `rename_by_name`: |
There was a problem hiding this comment.
One thing I did not think about is if there is already a newer file with the new filename, then it will stay the last revision for this filename.
We can't change the date of the renamed files, as that would change the order of the revisions.
There was a problem hiding this comment.
Correct that seems like expected behavior to me.
Fix DRIVERS-2808 and DRIVERS-2807
Please complete the following before merging:
GridFS\Bucket::deleteByName(filename)andrenameByName(filename, newFilename)mongo-php-library#1504