Skip to content

Commit a4265b3

Browse files
committed
Update GridFS spec to add delete_by_name and rename_by_name
1 parent bb21f78 commit a4265b3

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

source/gridfs/gridfs-spec.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,31 @@ orphaned chunks with files_id equal to id before raising the error.
649649

650650
If a networking or server error occurs, drivers MUST raise an error.
651651

652+
### File deletion by filename
653+
654+
To rename all revisions of a stored file with the specified filename, drivers SHOULD provide the method `delete_by_name`:
655+
656+
```javascript
657+
class GridFSBucket {
658+
659+
/**
660+
* Deletes all stored files with the specified @filename from a GridFS bucket.
661+
*/
662+
void delete_by_name(string filename);
663+
664+
}
665+
```
666+
667+
This method is an optimisation over deleting each revision of a stored file individually.
668+
669+
**Implementation details:**
670+
671+
Drivers MUST first find the `_id` field of all files collection documents with the given filename.
672+
Drivers MUST then delete all chunks with `files_id` in the found ids that was just deleted.
673+
Drivers MUST then delete all files collection documents with the found ids.
674+
675+
If there are no files collection documents with the given filename, drivers MUST raise an error.
676+
652677
### Generic Find on Files Collection
653678

654679
```javascript
@@ -814,18 +839,40 @@ class GridFSBucket {
814839
}
815840
```
816841

817-
Sets the filename field in the stored file"s files collection document to the new filename.
842+
Sets the filename field in the stored file's files collection document to the new filename.
818843

819844
**Implementation details:**
820845

821846
Drivers construct and execute an update_one command on the files collection using `{ _id: @id }` as the filter and
822847
`{ $set : { filename : "new_filename" } }` as the update parameter.
823848

824-
To rename multiple revisions of the same filename, users must retrieve the full list of files collection documents for a
849+
If `renameByName` is not implemented to rename multiple revisions of the same filename, users must retrieve the full list of files collection documents for a
825850
given filename and execute "rename" on each corresponding `_id`.
826851

827852
If there is no file with the given id, drivers MUST raise an error.
828853

854+
### Renaming stored files by filename
855+
856+
To rename all revisions of a stored file with the specified filename, drivers SHOULD provide the method `rename_by_name`:
857+
858+
```javascript
859+
class GridFSBucket {
860+
861+
/**
862+
* Renames all revisions of the stored file with the specified @filename.
863+
*/
864+
void rename_by_name(string filename, string new_filename);
865+
866+
}
867+
```
868+
869+
**Implementation details:**
870+
871+
Drivers construct and execute an update_many command on the files collection using `{ filename: @filename }` as the filter
872+
and `{ $set : { filename : "new_filename" } }` as the update parameter.
873+
874+
If there is no file with the given filename, drivers MUST raise an error.
875+
829876
### Dropping an entire GridFS bucket
830877

831878
```javascript
@@ -1042,6 +1089,7 @@ system?") it is a potential area of growth for the future.
10421089

10431090
## Changelog
10441091

1092+
- 2024-10-30: Add `delete_by_name` and `rename_by_name`
10451093
- 2024-10-28: Removed deprecated fields from tests: `md5`, `contentType`, `aliases`
10461094
- 2024-02-27: Migrated from reStructuredText to Markdown.
10471095
- 2016-05-10: Support custom file ids

0 commit comments

Comments
 (0)