@@ -375,65 +375,48 @@ Rename Files
375
375
------------
376
376
377
377
Use the ``MongoDB\GridFS\Bucket::rename()`` method to update the name of
378
- a GridFS file in your bucket. Pass the following parameters to the ``rename()``
379
- method:
380
-
381
- - ``_id`` value of the file you want to rename
382
- - New file name
378
+ a GridFS file in your bucket. You must specify the file to rename by its
379
+ ``_id`` field rather than its file name.
383
380
384
381
The following example shows how to update the ``filename`` field to
385
- ``'new_file_name'`` by referencing a file 's ``_id`` value :
382
+ ``'new_file_name'`` by referencing a document 's ``_id`` field :
386
383
387
384
.. literalinclude:: /includes/write/gridfs.php
388
385
:language: php
389
386
:dedent:
390
- :start-after: start-rename-files-id
391
- :end-before: end-rename-files-id
392
-
393
- Alternatively, you can use the ``MongoDB\GridFS\Bucket::renameByName()``
394
- method to rename a GridFS file and all its file revisions. Pass the
395
- following parameters to the ``renameByName()`` method:
387
+ :start-after: start-rename-files
388
+ :end-before: end-rename-files
396
389
397
- - ``filename`` value you want to change
398
- - New file name
390
+ .. note:: File Revisions
399
391
400
- The following example renames all files that have a ``filename`` value
401
- of ``'my_file'``:
402
-
403
- .. literalinclude:: /includes/write/gridfs.php
404
- :language: php
405
- :dedent:
406
- :start-after: start-rename-files-name
407
- :end-before: end-rename-files-name
392
+ The ``rename()`` method supports updating the name of only one file at
393
+ a time. If you want to rename each file revision, or files with different upload
394
+ times that share the same file name, collect the ``_id`` values of each revision.
395
+ Then, pass each value in separate calls to the ``rename()`` method.
408
396
409
397
.. _gridfs-delete-files:
410
398
411
399
Delete Files
412
400
------------
413
401
414
- Use the ``MongoDB\GridFS\Bucket::delete()`` method to remove a GridFS file's collection
402
+ Use the ``MongoDB\GridFS\Bucket::delete()`` method to remove a file's collection
415
403
document and associated chunks from your bucket. This effectively deletes the file.
416
- Pass the ``_id`` value of the file you want to delete as a parameter to the
417
- ``delete()`` method.
404
+ You must specify the file by its ``_id`` field rather than its file name.
418
405
419
406
The following example shows you how to delete a file by referencing its ``_id`` field:
420
407
421
408
.. literalinclude:: /includes/write/gridfs.php
422
409
:language: php
423
410
:dedent:
424
- :start-after: start-delete-files-id
425
- :end-before: end-delete-files-id
411
+ :start-after: start-delete-files
412
+ :end-before: end-delete-files
426
413
427
- Alternatively, you can use the ``MongoDB\GridFS\Bucket::deleteByName()`` method
428
- to delete a GridFS file and all its file revisions. Pass the ``filename`` value of the
429
- file you want to delete as a parameter to the ``deleteByName()`` method, as shown
430
- in the following code:
414
+ .. note:: File Revisions
431
415
432
- .. literalinclude:: /includes/write/gridfs.php
433
- :language: php
434
- :dedent:
435
- :start-after: start-delete-files-name
436
- :end-before: end-delete-files-name
416
+ The ``delete()`` method supports deleting only one file at a time. If
417
+ you want to delete each file revision, or files with different upload
418
+ times that share the same file name, collect the ``_id`` values of each revision.
419
+ Then, pass each value in separate calls to the ``delete()`` method.
437
420
438
421
API Documentation
439
422
-----------------
0 commit comments