You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/gridfs/gridfs-spec.md
+50-2Lines changed: 50 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -649,6 +649,31 @@ 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 `delete_by_name`:
655
+
656
+
```javascript
657
+
classGridFSBucket {
658
+
659
+
/**
660
+
* Deletes all stored files with the specified @filename from a GridFS bucket.
661
+
*/
662
+
voiddelete_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
+
652
677
### Generic Find on Files Collection
653
678
654
679
```javascript
@@ -814,18 +839,40 @@ class GridFSBucket {
814
839
}
815
840
```
816
841
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.
818
843
819
844
**Implementation details:**
820
845
821
846
Drivers construct and execute an update_one command on the files collection using `{ _id: @id }` as the filter and
822
847
`{ $set : { filename : "new_filename" } }` as the update parameter.
823
848
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
825
850
given filename and execute "rename" on each corresponding `_id`.
826
851
827
852
If there is no file with the given id, drivers MUST raise an error.
828
853
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
+
classGridFSBucket {
860
+
861
+
/**
862
+
* Renames all revisions of the stored file with the specified @filename.
0 commit comments