@@ -649,6 +649,32 @@ orphaned chunks with files_id equal to id before raising the error.
649
649
650
650
If a networking or server error occurs, drivers MUST raise an error.
651
651
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
+
652
678
### Generic Find on Files Collection
653
679
654
680
``` javascript
@@ -821,11 +847,34 @@ Sets the filename field in the stored file's files collection document to the ne
821
847
Drivers construct and execute an update_one command on the files collection using ` { _id: @id } ` as the filter and
822
848
` { $set : { filename : "new_filename" } } ` as the update parameter.
823
849
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 ` .
826
852
827
853
If there is no file with the given id, drivers MUST raise an error.
828
854
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
+
829
878
### Dropping an entire GridFS bucket
830
879
831
880
``` javascript
@@ -1042,6 +1091,7 @@ system?") it is a potential area of growth for the future.
1042
1091
1043
1092
## Changelog
1044
1093
1094
+ - 2024-10-30: Add ` delete_by_name ` and ` rename_by_name `
1045
1095
- 2024-10-28: Removed deprecated fields from tests: ` md5 ` , ` contentType ` , ` aliases `
1046
1096
- 2024-02-27: Migrated from reStructuredText to Markdown.
1047
1097
- 2016-05-10: Support custom file ids
0 commit comments