Skip to content

Commit 1154b60

Browse files
committed
Update GridFS spec to add delete_by_name and rename_by_name
1 parent c0435fd commit 1154b60

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

source/gridfs/gridfs-spec.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,32 @@ 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
655+
`delete_by_name`:
656+
657+
```javascript
658+
class GridFSBucket {
659+
660+
/**
661+
* Deletes all stored files with the specified @filename from a GridFS bucket.
662+
*/
663+
void delete_by_name(string filename);
664+
665+
}
666+
```
667+
668+
This method is an optimisation over deleting each revision of a stored file individually.
669+
670+
**Implementation details:**
671+
672+
Drivers MUST first find the `_id` field of all files collection documents with the given filename. Drivers MUST then
673+
delete all chunks with `files_id` in the found ids that was just deleted. Drivers MUST then delete all files collection
674+
documents with the found ids.
675+
676+
If there are no files collection documents with the given filename, drivers MUST raise an error.
677+
652678
### Generic Find on Files Collection
653679

654680
```javascript
@@ -821,11 +847,34 @@ Sets the filename field in the stored file's files collection document to the ne
821847
Drivers construct and execute an update_one command on the files collection using `{ _id: @id }` as the filter and
822848
`{ $set : { filename : "new_filename" } }` as the update parameter.
823849

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

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

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

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

10431092
## Changelog
10441093

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

0 commit comments

Comments
 (0)